<?php

include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Controllers.php';
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ValidatorController.php';
include dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'AdminModules.php';
include dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'lang_vi.php';

class AdminControllers extends Controllers {

    function __construct($aryConfigDB, $aryConfigs) {
        parent::__construct();
        $this->assign('root_page', $this->getRootPage());
        $this->assign('sub_domain', $this->getSubDomain());
        $this->_objConfig = $aryConfigs;
        $this->_objAdminModule = new AdminModules($aryConfigDB);
    }

    function __destruct() {
        
    }

    public function def() {
        $this->checkCookieLogin();

        if ($this->hasSession('login')) {
            $this->redirectURL($this->getRootPage() . '/quanly/manage/');
        } else {
            $this->assign('title', 'Đăng nhập');
            $this->setViewTemplate('admin/blackadmin', 'admin-login');
        }
    }

    public function adminLogin() {
        $loginData = array();
        $jsonData = array();
        $loginData = $this->getAllPostParams();
        $intOk = $this->_objAdminModule->selectLoginInfo($loginData, $result);
        if ($intOk == 1 && isset($result[0])) {
            $this->setSession('login', $result[0]);
            $this->setCookieData('userId', $result[0]['member_id']);
            $jsonData['intOk'] = $intOk;
            $jsonData['urlOk'] = $this->getRootPage() . '/quanly/manage/';
            $this->redirectURL($jsonData['urlOk']);
        } else {
            $jsonData['intOk'] = 0;
            $jsonData['urlError'] = $jsonData['urlOk'] = $this->getRootPage() . '/quanly/';
            $this->redirectURL($jsonData['urlError']);
        }
    }

    public function checkCookieLogin() {
        $hasCookie = $this->hasCookie('userId');
        $cookieData = $this->getCookieData('userId');
        if ($hasCookie && is_numeric($cookieData)) {
            $aryCondition = array();
            $aryCondition['member_id'] = $cookieData;
            $intOk = $this->_objAdminModule->selectLoginInfoByUser($aryCondition, $aryData);
            $this->setSession('login', $aryData[0]);
        }
    }

    public function checkSessionLogin() {
        if ($this->hasSession('login') == false) {
            $this->redirectURL($this->getRootPage() . '/quanly/');
//            return;
        }
    }

    public function manage() {
        $method_delivery = $this->getConfig('method_delivery');
        $method_payment = $this->getConfig('method_payment');
        $this->assign('method_payment', $method_payment);
        $this->assign('method_delivery', $method_delivery);
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryLocation = $this->getConfig('location');
        $aryMember = $this->getSession('login');
        $aryConf = $this->getConfig();
        $this->checkMemberPermission($aryMember['member_id']);
        $this->assign('loginName', $aryMember['member_login_name']);
        $this->assign('isMaster', $aryMember['member_is_master']);
        $this->assign('aryLocation', $aryLocation);
        $this->assign('aryProductStore', $aryConf['product_store']);
        $this->assign('aryProductWarranty', $aryConf['product_warranty']);
        $this->assign('aryProductOrigin', $aryConf['product_origin']);
        $this->assign('aryProductTrans', $aryConf['product_transportation']);
        $this->assign('aryProductType', $aryConf['product_type']);
        $this->assign('title', 'Trang quản lý');
        $this->setViewTemplate('admin/blackadmin', 'admin-index');
    }

    public function checkMemberPermission($memberId) {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $inOk = $this->_objAdminModule->getPermissionByMemberId($memberId, $aryMemberPermission);
        if (true == isset($aryMemberPermission[0])) {
            foreach ($aryMemberPermission as $key => $value) {
                // module product
                if ($value['member_permission_module'] == 1) {
                    $permissionProduct = $value['member_permission_module'];
                    $aryPermissionProduct = explode(',', $value['member_permission']);
                }
                //modul product category
                if ($value['member_permission_module'] == 2) {
                    $permissionProductCategory = $value['member_permission_module'];
                    $aryPermissionProductCategory = explode(',', $value['member_permission']);
                }
                //module hang san xuat
                if ($value['member_permission_module'] == 8) {
                    $permissionProductMaker = $value['member_permission_module'];
                    $aryPermissionProductMaker = explode(',', $value['member_permission']);
                }
                //module thong so ky thuat
                if ($value['member_permission_module'] == 7) {
                    $permissionProductSpecs = $value['member_permission_module'];
                    $aryPermissionProductSpecs = explode(',', $value['member_permission']);
                }
                //bao gia
                if ($value['member_permission_module'] == 9) {
                    $permissionProductPrice = $value['member_permission_module'];
                    $aryPermissionProductPrice = explode(',', $value['member_permission']);
                }
                //module tin tuc
                if ($value['member_permission_module'] == 3) {
                    $permissionNews = $value['member_permission_module'];
                    $aryPermissionNews = explode(',', $value['member_permission']);
                }
                //module danh muc tin tuc
                if ($value['member_permission_module'] == 4) {
                    $permissionNewsCategory = $value['member_permission_module'];
                    $aryPermissionNewsCategory = explode(',', $value['member_permission']);
                }
                //module don hang
                if ($value['member_permission_module'] == 5) {
                    $permissionOrder = $value['member_permission_module'];
                    $aryPermissionOrder = explode(',', $value['member_permission']);
                }
                //cho phep edit du lieu
                if ($value['member_permission_module'] == 6) {
                    $permissionEditOtherData = $value['member_permission_module'];
                }
            }
        }
        //tach tung loai quyen
        //product
        if (true == isset($aryPermissionProduct[0])) {
            foreach ($aryPermissionProduct as $key => $value) {
                if ($value == 1) {
                    $perProductAdd = $value;
                }
                if ($value == 2) {
                    $perProductEdit = $value;
                }
                if ($value == 3) {
                    $perProductDelete = $value;
                }
            }
        }
        //product category
        if (true == isset($aryPermissionProductCategory[0])) {
            foreach ($aryPermissionProductCategory as $key => $value) {
                if ($value == 1) {
                    $perProductCategoryAdd = $value;
                }
                if ($value == 2) {
                    $perProductCategoryEdit = $value;
                }
                if ($value == 3) {
                    $perProductCategoryDelete = $value;
                }
            }
        }
        //product maker
        if (true == isset($aryPermissionProductMaker[0])) {
            foreach ($aryPermissionProductMaker as $key => $value) {
                if ($value == 1) {
                    $perProductMakerAdd = $value;
                }
                if ($value == 2) {
                    $perProductMakerEdit = $value;
                }
                if ($value == 3) {
                    $perProductMakerDelete = $value;
                }
            }
        }
        //product specs
        if (true == isset($aryPermissionProductSpecs[0])) {
            foreach ($aryPermissionProductSpecs as $key => $value) {
                if ($value == 1) {
                    $perProductSpecsAdd = $value;
                }
                if ($value == 2) {
                    $perProductSpecsEdit = $value;
                }
                if ($value == 3) {
                    $perProductSpecsDelete = $value;
                }
            }
        }
        //product price
        if (true == isset($aryPermissionProductPrice[0])) {
            foreach ($aryPermissionProductPrice as $key => $value) {
                if ($value == 1) {
                    $perProductPriceAdd = $value;
                }
                if ($value == 2) {
                    $perProductPriceEdit = $value;
                }
                if ($value == 3) {
                    $perProductPriceDelete = $value;
                }
            }
        }
        //news
        if (true == isset($aryPermissionNews[0])) {
            foreach ($aryPermissionNews as $key => $value) {
                if ($value == 1) {
                    $perNewsAdd = $value;
                }
                if ($value == 2) {
                    $perNewsEdit = $value;
                }
                if ($value == 3) {
                    $perNewsDelete = $value;
                }
            }
        }
        //news category
        if (true == isset($aryPermissionNewsCategory[0])) {
            foreach ($aryPermissionNewsCategory as $key => $value) {
                if ($value == 1) {
                    $perNewsCategoryAdd = $value;
                }
                if ($value == 2) {
                    $perNewsCategoryEdit = $value;
                }
                if ($value == 3) {
                    $perNewsCategoryDelete = $value;
                }
            }
        }
        //don hang
        if (true == isset($aryPermissionOrder[0])) {
            foreach ($aryPermissionOrder as $key => $value) {
                if ($value == 1) {
                    $perOrderEdit = $value;
                }
                if ($value == 2) {
                    $perOrderDelete = $value;
                }
            }
        }
        //permission product
        $this->assign('perProduct', $permissionProduct);
        $this->assign('perProductAdd', $perProductAdd);
        $this->assign('perProductEdit', $perProductEdit);
        $this->assign('perProductDelete', $perProductDelete);
        //permission product category
        $this->assign('permissionProductCategory', $permissionProductCategory);
        $this->assign('perProductCategoryAdd', $perProductCategoryAdd);
        $this->assign('perProductCategoryEdit', $perProductCategoryEdit);
        $this->assign('perProductCategoryDelete', $perProductCategoryDelete);
        //permission product maker
        $this->assign('perProductMaker', $permissionProductMaker);
        $this->assign('perProductMakerAdd', $perProductMakerAdd);
        $this->assign('perProductMakerEdit', $perProductMakerEdit);
        $this->assign('perProductMakerDelete', $perProductMakerDelete);
        //permission product specs
        $this->assign('permissionProductSpecs', $permissionProductSpecs);
        $this->assign('perProductSpecsAdd', $perProductSpecsAdd);
        $this->assign('perProductSpecsEdit', $perProductSpecsEdit);
        $this->assign('perProductSpecsDelete', $perProductSpecsDelete);
        //permission product price
        $this->assign('permissionProductPrice', $permissionProductPrice);
        $this->assign('perProductPriceAdd', $perProductPriceAdd);
        $this->assign('perProductPriceEdit', $perProductPriceEdit);
        $this->assign('perProductPriceDelete', $perProductPriceDelete);
        //permission news
        $this->assign('permissionNews', $permissionNews);
        $this->assign('perNewsAdd', $perNewsAdd);
        $this->assign('perNewsEdit', $perNewsEdit);
        $this->assign('perNewsDelete', $perNewsDelete);
        //permission news category
        $this->assign('permissionNewsCategory', $permissionNewsCategory);
        $this->assign('perNewsCategoryAdd', $perNewsCategoryAdd);
        $this->assign('perNewsCategoryEdit', $perNewsCategoryEdit);
        $this->assign('perNewsCategoryDelete', $perNewsCategoryDelete);
        //permission order
        $this->assign('permissionOrder', $permissionOrder);
        $this->assign('perOrderEdit', $perOrderEdit);
        $this->assign('perOrderDelete', $perOrderDelete);
        //permission edit other's member data
        $this->assign('permissionEditOtherData', $permissionEditOtherData);
        //permission product specs
        //permission product maker
    }

    public function procesMultiUpload() {
        $subDomain = $this->getSubDomain();
        $imageDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR;
        $this->multiUploadFile('test', $imageDir, $resultFileUpLoaded, $this->getConfig('img_in_content_size'));
        $imageUrl = $subDomain . '/images/upload/content/' . $resultFileUpLoaded[0]['image_name'];
        $imageStr = "<p class='show_image' style='text-align: center;'><img src='$imageUrl' align='center' /></p>";
        echo $imageStr;
    }

    public function getListProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $orderType = $this->getParam('orderType');
        $page = $this->getParam('page');
        $categoryId = $this->getParam('catId');
        $aryConditions = array();
        $aryConditions['record_per_page'] = $this->getConfig('product_per_page');
        $aryConditions['current_page'] = $page;
        if ($orderType == 'date-up') {
            $aryConditions['field'] = 'product_updated_date';
            $aryConditions['order'] = 'ASC';
        } else if ($orderType == 'date-down') {
            $aryConditions['field'] = 'product_updated_date';
            $aryConditions['order'] = 'DESC';
        } else if ($orderType == 'price-up') {
            $aryConditions['field'] = 'product_price_vnd';
            $aryConditions['order'] = 'ASC';
        } else if ($orderType == 'price-down') {
            $aryConditions['field'] = 'product_price_vnd';
            $aryConditions['order'] = 'DESC';
        } else if ($orderType == 'id-down') {
            $aryConditions['field'] = 'product_id';
            $aryConditions['order'] = 'DESC';
        } else if ($orderType == 'id-up') {
            $aryConditions['field'] = 'product_id';
            $aryConditions['order'] = 'ASC';
        }

        $aryCategory = array();

        $this->_objAdminModule->getCategory($aryCategory);

        $aryCategoryLevel1 = array();

        foreach ($aryCategory as $key => $value) {
            if ($value['category_parent'] == 0) {
                $aryCategoryLevel1[$key]['category_id'] = $value['category_id'];
                $aryCategoryLevel1[$key]['category_name'] = $value['category_name'];
                $aryCategoryLevel1[$key]['category_total_child'] = $value['category_total_child'];
            }
        }

        $listCategoryId = $this->buildListCategory($categoryId);

        $productMakerId = $this->getParam('makerId');

        $aryConditions['product_maker_id'] = $productMakerId;

        $intOk = $this->_objAdminModule->getProduct($aryConditions, $listCategoryId, $aryProduct);

        $intOk = $this->_objAdminModule->getProductMakerForAddProduct($aryProductMaker);

        $aryCategoryId = explode(",", $listCategoryId);

        $aryMaker = array();

        foreach ($aryProductMaker as $key => $value) {
            if (in_array($value['product_maker_category_category_id'], $aryCategoryId)) {
                $aryMaker[$value['product_maker_id']]['product_maker_category_category_id'] = $value['product_maker_category_category_id'];
                $aryMaker[$value['product_maker_id']]['product_maker_id'] = $value['product_maker_id'];
                $aryMaker[$value['product_maker_id']]['product_maker_name'] = $value['product_maker_name'];
            }
        }

        $strCatOption = $this->buildTreeCategoryOption($aryCategory);

        $this->assign('strCatOption', $strCatOption);

        $this->assign('productMakerId', $productMakerId);

        $this->assign('aryMaker', $aryMaker);

        $this->assign('aryProductMaker', $aryProductMaker);

        $this->setActionJSPaging("AdminController.getListProduct('$orderType','$categoryId','$productMakerId',");

        $strPaging = $this->AjaxPagination($aryProduct['paging']);
        $this->assign('strPaging', $strPaging);
        $aryPostParam = $this->getAllPostParams();
        $this->assign('perProductAdd', $aryPostParam['perProductAdd']);
        $this->assign('perProductEdit', $aryPostParam['perProductEdit']);
        $this->assign('perProductDelete', $aryPostParam['perProductDelete']);
        $this->assign('isMaster', $aryPostParam['isMaster']);
        $this->assign('aryProduct', $aryProduct['data']);
        $this->assign('categoryId', $categoryId);
        $this->assign('orderType', $orderType);
        $this->assign('page', $page);
        $strCategory = $this->buildTreeCatForListProduct($aryCategory, $categoryId);
        $this->assign('aryCategory', $aryCategory);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['listProduct'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-product');
        $aryResult['listCategory'] = $strCategory;
        $aryResult['categoryId'] = $categoryId;
        $aryResult['aryCategory'] = $aryCategoryLevel1;
        $aryResult['listProductMaker'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-sub-cat-hidden');
        echo json_encode($aryResult);
    }

    public function buildListCategory($categoryId) {

        $aryChildCategory = $this->getChildCat($categoryId);

        if (isset($aryChildCategory[0])) {

            array_push($aryChildCategory, $categoryId);

            $listCategoryId = implode(',', $aryChildCategory);
        } else {
            $listCategoryId = $categoryId;
        }

        return $listCategoryId;
    }

    public function buildTreeCategoryOption($catData, $prentsID = 0) {
        $specs = '&nbsp;';
        foreach ($catData as $aCat) {

            if ($aCat['category_parent'] == $prentsID) {
                if ($aCat['category_level'] == 0) {
                    $style = 'style=color:#F58516;';
                }
                if ($aCat['category_level'] == 1) {
                    $specs = '&nbsp;&nbsp;&nbsp;';
                }
                if ($aCat['category_level'] == 2) {
                    $specs = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }
                if ($aCat['category_level'] == 3) {
                    $specs = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }
                $catList .= "<option value=" . $aCat['category_id'] . "  $style>" . $specs . $aCat['category_name'] . "</option>";
                $catList .= $this->buildTreeCategoryOption($catData, $aCat['category_id']);
            }
        }
        return $catList;
    }

    public function deleteProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $productId = $this->getParam('productId');
        $page = $this->getParam('page');
        $categoryId = $this->getParam('categoryId');
        $intOk = $this->_objAdminModule->getProductById($productId, $aryData);
        $mainImage = $aryData[0]['product_main_image'];
        $smallImage = $aryData[0]['product_small_image'];
        $largeImage = $aryData[0]['product_large_image'];
        $this->deleteImage($mainImage, 'main');
        $this->deleteImage($smallImage, 'small');
        $this->deleteImage($largeImage, 'large');
        $aryConfig = array(
            array(
                'keyword' => 'WHERE',
                'field' => 'product_id',
                'math' => '=',
                'value' => $productId
            )
        );
        $aryDelete = array();
        $aryDelete['product_del_flag'] = 1;
        $intOk = $this->_objAdminModule->deleteProductByProductId($aryDelete, $aryConfig);
        if ($intOk == 1) {
            $this->_objAdminModule->deleteProductSpecsByProcutId($productId);
            $aryConditions = array();
            $aryConditions['record_per_page'] = $this->getConfig('product_per_page');
            $aryConditions['current_page'] = $page;
            $listCategoryId = $this->buildListCategory($categoryId);
            $this->_objAdminModule->getProductTotalPage($aryConditions, $listCategoryId, $aryProduct);
            if ($aryProduct['paging']['total_page'] < $page) {
                $page = $page - 1;
            }
        }

        $aryCatParentId = $this->_objAdminModule->getCategoryParentPath($categoryId);

        array_push($aryCatParentId, $categoryId);

        foreach ($aryCatParentId as $key => $value) {

            $this->setFlagProductCache($value);
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['page'] = $page;
        $aryResult['messageDeleteSuccess'] = _PRODUCT_DELETE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function showEditorAddProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $intOk = $this->_objAdminModule->getProductMakerForAddProduct($aryProductMaker);
        $this->assign('aryProductMaker', $aryProductMaker);
        $aryResult = array();
        $aryResult['listProductMaker'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-sub-cat-hidden');
        echo json_encode($aryResult);
    }

    public function getProductCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryCategory = array();
        $parentCategoryId = $this->getParam('parentCatId');
        $ulId = $this->getParam('ulId');
        $nextUlId = $ulId + 1;
        $intOk = $this->_objAdminModule->getSubCatByCatId($parentCategoryId, $aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $this->assign('ulId', $ulId);
        $this->assign('nextUlId', $nextUlId);
        $this->assign('parentCategoryId', $parentCategoryId);
//        foreach ($aryCategory as $key => $value) {
//            if ($value['category_level'] == 1) {
//                $aryAllCatData[$value['category_id']]['category_id'] = $value['category_id'];
//                $aryAllCatData[$value['category_id']]['category_name'] = $value['category_name'];
//            }
//            if ($value['category_level'] == 2) {
//                $aryAllCatData[$value['category_parent']]['sub_category'][$value['category_id']]['category_id'] = $value['category_id'];
//                $aryAllCatData[$value['category_parent']]['sub_category'][$value['category_id']]['category_name'] = $value['category_name'];
//            }
//        }
        $this->assign('aryAllCategory', $aryAllCatData);
        $aryPostParam = $this->getAllPostParams();
        $this->assign('perProductCategoryAdd', $aryPostParam['perProductCategoryAdd']);
        $this->assign('perProductCategoryEdit', $aryPostParam['perProductCategoryEdit']);
        $this->assign('perProductCategoryDelete', $aryPostParam['perProductCategoryDelete']);
        $this->assign('isMaster', $aryPostParam['isMaster']);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['ulId'] = $ulId;
        $aryResult['nextUlId'] = $nextUlId;
        $aryResult['listCategory'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-category');
        $aryResult['contentCategory'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-content-category');
        echo json_encode($aryResult);
    }

    public function getListCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryCategory = array();
        $parentId = 0;
        $intOk = $this->_objAdminModule->getSubCatByCatId($parentId, $aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product-category-merge');
        echo json_encode($aryResult);
    }

    public function getListCategoryFrom() {
        $parentId = $this->getParam('categoryId');
        $nextItem = $this->getParam('listIndex');
        $intOk = $this->_objAdminModule->getSubCatByCatId($parentId, $aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $this->assign('nextItem', $nextItem + 1);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['currentList'] = 'list_from_';
        $aryResult['liId'] = $parentId;
        $aryResult['listIndex'] = $nextItem;
        $aryResult['nextItem'] = $nextItem + 1;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product-category-merge-sub');
        echo json_encode($aryResult);
    }

    public function getListCategoryTo() {
        $parentId = $this->getParam('categoryId');
        $nextItem = $this->getParam('listIndex');
        $intOk = $this->_objAdminModule->getSubCatByCatId($parentId, $aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $this->assign('nextItem', $nextItem + 1);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['nextItem'] = $nextItem + 1;
        $aryResult['currentList'] = 'list_to_';
        $aryResult['liId'] = $parentId;
        $aryResult['listIndex'] = $nextItem;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product-category-merge-sub-to');
        echo json_encode($aryResult);
    }

    public function saveMergeCategory() {
        $aryParam = $this->getAllPostParams();
//        print_r($aryParam);
        $aryError = array();
        $fromCategory = $aryParam['from_category'][0];
//        echo $fromCategory;
        $toCategory = $aryParam['to_category'][0];
//        echo $toCategory;
        if ($fromCategory == '') {
            $aryError[] = 'Bạn chưa chọn danh mục muốn chuyển';
        }
        if ($toCategory == '') {
            $aryError[] = 'Bạn chưa chọn danh mục cần chuyển sang';
        }
        if ($fromCategory == $toCategory) {
            $aryError[] = 'Bạn không thể chuyển cùng một danh mục.';
        } else {
            $this->_objAdminModule->checkLevelCategory($fromCategory, $aryFromCategoryLevel);
            $this->_objAdminModule->checkLevelCategory($toCategory, $aryToCategoryLevel);
            $categoryFromLevel = $aryFromCategoryLevel[0]['category_level'];
            $categoryToLevel = $aryToCategoryLevel[0]['category_level'];
            $aryParentFromCategory = $this->_objAdminModule->getCategoryParentPath($fromCategory);
            $aryParentToCategory = $this->_objAdminModule->getCategoryParentPath($toCategory);
//            print_r($aryFromCategoryLevel);
//            print_r($aryToCategoryLevel);
//            print_r($aryParentFromCategory);
            if ($categoryFromLevel == $categoryToLevel + 1 && in_array($toCategory, $aryParentFromCategory)) {
                $aryError[] = 'Danh mục bạn muốn chuyển đang là danh mục con của danh mục chuyển sang.';
            }
            if ($categoryFromLevel == 0 && in_array($fromCategory, $aryParentToCategory)) {
                $aryError[] = 'Bạn không thể chuyển danh mục cấp cao nhất xuống danh mục con của nó';
            }
        }
        $aryResult = array();
        if (count($aryError) > 0) {
            $aryResult['intOk'] = -2;
            $aryResult['strError'] = $aryError[0];
            echo json_encode($aryResult);
            return;
        }


        $parentCurrentFromCategory = array_pop($aryParentFromCategory);
        $this->_objAdminModule->getTotalChildOfParentCategory($parentCurrentFromCategory, $aryTotalChildOfFromCategory);
        $totalChildOfFromCategory = $aryTotalChildOfFromCategory[0]['category_total_child'];
        $this->_objAdminModule->getTotalChildOfParentCategory($toCategory, $aryTotalChildToCategory);
        $totalChildToCategory = $aryTotalChildToCategory[0]['category_total_child'];

//        echo $totalChildOfFromCategory;
//        echo $totalChildToCategory;
        $aryParentFromCategoryUpdate = array();
        $aryParentFromCategoryUpdate['category_parent'] = $toCategory;
        $aryParentFromCategoryUpdate['category_level'] = $categoryToLevel + 1;
//        print_r($aryParentFromCategoryUpdate);
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'category_id',
                'value' => $fromCategory,
                'math' => '='
            )
        );

        $intOk = $this->_objAdminModule->updateParentFromCategory($aryParentFromCategoryUpdate, $aryConfig);

        if ($intOk == 1) {
            if ($totalChildOfFromCategory > 0) {
                $aryFromCategoryTotalChildUpdate = array();
                $aryFromCategoryTotalChildUpdate['category_total_child'] = $totalChildOfFromCategory - 1;
                $aryFromCategoryConfig = array(
                    array(
                        'keyword' => 'where',
                        'field' => 'category_id',
                        'value' => $parentCurrentFromCategory,
                        'math' => '='
                    )
                );
                $intOk = $this->_objAdminModule->updateCategoryTotalChild($aryFromCategoryTotalChildUpdate, $aryFromCategoryConfig);
            }

            $aryTotalChildToCategoryUpdate = array();
            $aryTotalChildToCategoryUpdate['category_total_child'] = $totalChildToCategory + 1;

            $aryToCategoryConfig = array(
                array(
                    'keyword' => 'where',
                    'field' => 'category_id',
                    'value' => $toCategory,
                    'math' => '='
                )
            );

            $intOk = $this->_objAdminModule->updateCategoryTotalChild($aryTotalChildToCategoryUpdate, $aryToCategoryConfig);
        }

        $this->setFlagProductByCategoryCache($fromCategory);

        $this->setFlagProductByCategoryCache($toCategory);

        $this->setFlagByCategoryCache($fromCategory);

        $this->setFlagByCategoryCache($toCategory);

        $this->setFlagRootCategoryCache();

        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = 'Danh mục đã được chuyển';
        echo json_encode($aryResult);
    }

    public function saveMainCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $aryCategory = $aryParam['category_name_level1'];
        $intOk = -2;
        foreach ($aryCategory as $key => $value) {
            if (strlen(trim($value)) > 0) {
                $aryInsertCategory = array();
                $aryInsertCategory['category_name'] = $value;
                $aryInsertCategory['category_parent'] = 0;
                $aryInsertCategory['category_level'] = 1;
                $aryInsertCategory['category_name_filter'] = $this->filterUnicode($value);
                $intOk = $this->_objAdminModule->insertCategory($aryInsertCategory);
            }
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        echo json_encode($aryResult);
    }

    public function showAddSubCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $intOk = $this->_objAdminModule->getSubCatByCatId(0, $aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'admin-show-sub-category');
        echo json_encode($aryResult);
    }

    public function showAddProductMaker() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $intOk = $this->_objAdminModule->getSubCatByCatId(0, $aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product_show_add_maker');
        echo json_encode($aryResult);
    }

    public function showAddSpecs() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $intOk = $this->_objAdminModule->getSubCatByCatId(0, $aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product_show_add_specs');
        echo json_encode($aryResult);
    }

    public function showSpecsByCatId() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;

        $categoryId = $this->getParam('categoryId');

        $this->_objAdminModule->getCategoryById($categoryId, $aryCategory);

        $categoryName = $aryCategory[0]['category_name'];

        if ($aryCategory[0]['category_total_child'] > 0) {
            $aryResult = array();
            $intOk = -2;
            $aryResult['intOk'] = $intOk;
            echo json_encode($aryResult);
            return;
        }

        $this->_objAdminModule->getSpecsByCategoryId($categoryId, 0, $arySpecs);

        $this->assign('arySpecs', $arySpecs);

        $this->assign('categoryName', $aryCategory[0]['category_name']);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['listSpecs'] = $this->getViewTemplate('admin/blackadmin', 'product_specs_list_for_add');
        echo json_encode($aryResult);
    }

    public function showProductMakerForAddMaker() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $categoryId = $this->getParam('categoryId');

        $intOk = $this->_objAdminModule->getCategoryById($categoryId, $aryCategory);

        $categoryName = $aryCategory[0]['category_name'];

        if ($aryCategory[0]['category_total_child'] > 0) {
            $aryResult = array();
            $aryResult['hasProductMaker'] = 0;
            echo json_encode($aryResult);
            return;
        }

        $this->_objAdminModule->getProductMakerByCatId($categoryId, $aryProductMakerCategory);

        $aryProductMakerId = array();

        if (isset($aryProductMakerCategory[0])) {

            foreach ($aryProductMakerCategory as $key => $value) {

                $aryProductMakerId[] = $value['product_maker_category_maker_id'];
            }
        }


        $this->_objAdminModule->getProductMaker($aryProductMaker);

        $aryCurrentMaker = array();

        $aryOtherMaker = array();

        foreach ($aryProductMaker as $key => $value) {
            if (in_array($value['product_maker_id'], $aryProductMakerId)) {
                $aryCurrentMaker[$key]['product_maker_name'] = $value['product_maker_name'];
                $aryCurrentMaker[$key]['product_maker_main_logo'] = $value['product_maker_main_logo'];
            } else {
                $aryOtherMaker[$key]['product_maker_id'] = $value['product_maker_id'];
                $aryOtherMaker[$key]['product_maker_name'] = $value['product_maker_name'];
                $aryOtherMaker[$key]['product_maker_main_logo'] = $value['product_maker_main_logo'];
            }
        }

        $hasCurrentProductMaker = 0;

        $hasOtherProductMaker = 0;

        $hasProductMaker = 0;

        if (count($aryCurrentMaker) > 0) {

            $hasCurrentProductMaker = 1;
        }

        if (count($aryOtherMaker) > 0) {

            $hasOtherProductMaker = 1;
        }

        if ($hasCurrentProductMaker == 1 || $hasOtherProductMaker == 1) {

            $hasProductMaker = 1;
        }

        $this->assign('categoryName', $categoryName);

        $this->assign('hasCurrentProductMaker', $hasCurrentProductMaker);

        $this->assign('hasOtherProductMaker', $hasOtherProductMaker);

        $this->assign('aryCurrentProductMaker', $aryCurrentMaker);

        $this->assign('aryOtherProductMaker', $aryOtherMaker);

        $aryResult = array();

        $aryResult['hasProductMaker'] = $hasProductMaker;

        $aryResult['aryCurrentProductMaker'] = $this->getViewTemplate('admin/blackadmin', 'product_maker_list_current_maker');



        echo json_encode($aryResult);
    }

    public function saveSpecs() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $aryParam = $this->getAllPostParams();

        $arySpecsName = $aryParam['specs_name'];

        $arySpecsIsShow = $aryParam['specs_is_show'];

        $parentSpectId = $aryParam['specs_id'];

        $aryInputType = $aryParam['specs_input_type'];

        $specsCategoryId = $aryParam['specs_category_id'];

        $type = $this->getParam('type');

        $aryError = array();

        $count = 0;

        $countInput = count($arySpecsName);

        foreach ($arySpecsName as $key => $value) {
            if (trim($value) == '') {
                $count++;
            }
        }

        if ($countInput == $count) {
            $intOk = -2;
            $aryError[] = _EMPTY_SPECS;
        }

        if (count($aryError) > 0) {
            $aryResult = array();
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = join('<br>', $aryError);
            echo json_encode($aryResult);
            return;
        }

        //after validate
        if ($parentSpectId == 0) {
            $level = 0;
        } else {
            $aryLevel = $this->_objAdminModule->getSecsParentPath($parentSpectId);
            $level = count($aryLevel) + 1;
        }

        $totalChild = 0;

        foreach ($arySpecsName as $key => $value) {
            if (trim($value) != '') {
                $arySpecs = array();
                $arySpecs['specs_category_id'] = $specsCategoryId;
                $arySpecs['specs_parent'] = $parentSpectId;
                $arySpecs['specs_level'] = $level;
                $arySpecs['specs_name'] = $value;
                $arySpecs['specs_input_type'] = $aryInputType[$key];
                $arySpecs['specs_is_show'] = $arySpecsIsShow[$key];
                $totalChild++;
                $intOk = $this->_objAdminModule->insertSpecs($arySpecs);
            }
        }

        if ($intOk == 1 && $parentSpectId != 0) {
            $intOk = $this->_objAdminModule->updateSpecsNumOfChild($parentSpectId, $totalChild);
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['messageSuccess'] = _SPECS_SAVE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function saveSubCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $parentCategoryId = $aryParam['category_id_hidden'];
        $arySubCatName = $aryParam['sub_category_name'];
        $aryIsShow = $aryParam['category_is_show'];
        $count = 0;
        $coutInput = count($arySubCatName);
        $aryFile = $_FILES['image_category']['name'];
        $aryError = array();
        $aryResult = array();
        $intOk = 1;
        if ($parentCategoryId == '') {
            $aryError[] = 'Bạn chưa chọn danh mục cha.';
        }

        foreach ($arySubCatName as $key => $value) {
            if (trim($value) == '') {
                $count++;
            }
            if (trim($value) != '' && $aryFile[$key] == '') {
                $aryError[] = 'Bạn chưa chọn ảnh đại diện cho danh mục ' . $value . '.';
            }
        }
        if ($count == $coutInput) {
            $aryError[] = 'Bạn chưa nhập tên danh mục con.';
        }
        $flag = $this->checkAllowImage('image_category');
        if ($flag == false) {
            $aryError[] = 'Bạn chỉ được upload file ảnh (jpg, jpeg, gif, png).';
        }
        $flag = $this->checkFileSizeUpload('image_category', 1048576);
        if ($flag == false) {
            $aryError[] = 'Dung lượng file Upload không được lớn hơn 1 MB.';
        }
        if (count($aryError) > 0) {
            $intOk = -2;
            $strError = join("<br>", $aryError);
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = $strError;
            echo json_encode($aryResult);
            return;
        }

        $imageDir = $this->getImageUploadDir("main");

        $imageSmallDir = $this->getImageUploadDir("small");

        $imageLargeDir = $this->getImageUploadDir("large");

        //main image
        $this->multiUploadFile('image_category', $imageDir, $resultMainImage, $this->getConfig('img_category_main_size'));
        //small image for link tin tuc
        $this->multiUploadFile('image_category', $imageSmallDir, $resultSmallImage, $this->getConfig('img_category_small_size'));
        //large image
        $this->multiUploadFile('image_category', $imageLargeDir, $resultLargeImage, $this->getConfig('img_category_lager_size'));

        if ($parentCategoryId == 0) {

            $level = 0;
        } else {
            $aryLevel = $this->_objAdminModule->getCategoryParentPath($parentCategoryId);

            $level = count($aryLevel) + 1;

            array_push($aryLevel, $parentCategoryId);

            foreach ($aryLevel as $key => $value) {

                $this->setFlagCategoryCache($value);
            }
        }
        $totalChild = 0;
        foreach ($arySubCatName as $key => $value) {
            if (trim($value) != '' && $resultMainImage[$key] != '') {
                $imageMainLocation = '';
                $imageSmallLocation = '';
                $imageLargeLocation = '';
                $imageMainLocation = $imageDir . $resultMainImage[$key]['image_name'];
                $imageSmallLocation = $imageSmallDir . $resultSmallImage[$key]['image_name'];
                $imageLargeLocation = $imageLargeDir . $resultLargeImage[$key]['image_name'];

                $imageExtension = '';
                $imageExtension = strtolower(substr($resultMainImage[$key]['image_name'], strlen($resultMainImage[$key]['image_name']) - 4, 4));
                $newImageName = '';
                $newImageName = $this->filterUnicode($value) . $imageExtension;
                rename($imageMainLocation, $imageDir . $newImageName);
                rename($imageSmallLocation, $imageSmallDir . $newImageName);
                rename($imageLargeLocation, $imageLargeDir . $newImageName);
                $aryCategoryInsert = array();
                $aryCategoryInsert['category_name'] = $value;
                $aryCategoryInsert['category_parent'] = $parentCategoryId;
                $aryCategoryInsert['category_level'] = $level;
                $aryCategoryInsert['category_keyword'] = $value . ',' . $this->removeUnicode($value);
                $aryCategoryInsert['category_title_header'] = $value;
                $aryCategoryInsert['category_description'] = $value;
                $aryCategoryInsert['category_name_filter'] = $this->filterUnicode($value);
                $aryCategoryInsert['category_main_image'] = $resultMainImage[$key]['image_name'];
                $aryCategoryInsert['category_small_image'] = $resultSmallImage[$key]['image_name'];
                $aryCategoryInsert['category_large_image'] = $resultLargeImage[$key]['image_name'];
                $aryCategoryInsert['category_is_show'] = $aryIsShow[$key];
                $intOk = $this->_objAdminModule->insertCategory($aryCategoryInsert, $lastCategoryId);
                if ($intOk == 1) {
                    $config = array(
                        array(
                            'keyword' => 'WHERE',
                            'field' => 'category_id',
                            'math' => '=',
                            'value' => $lastCategoryId
                        )
                    );
                    $aryCatEdit = array();
                    $aryCatEdit['category_order'] = $lastCategoryId;
                    $intOk = $this->_objAdminModule->editCatById($aryCatEdit, $config);
                }

                $totalChild++;
            }
        }

        if ($intOk == 1 && $parentCategoryId != 0) {
            $intOk = $this->_objAdminModule->updateCatNumOfChild($parentCategoryId, $totalChild);
        }

        $this->setFlagRootCategoryCache();

        $aryResult['intOk'] = $intOk;
        $aryResult['successMessage'] = 'Danh mục đã được tạo.';
        echo json_encode($aryResult);
    }

    public function buildCategoryHtmlCache($categoryId) {

        $this->_objAdminModule->getSubCatByCatId($categoryId, $aryCategory);

        $aryCategoryParent = $this->buildParentList($categoryId);

        $this->assign('categoryParent', $aryCategoryParent);
    }

    public function buildMenuHtmlCache() {
        $intOk = $this->_objAdminModule->getProductCategory($aryProductCategory);
        $aryRootCategory = array();
        $arySubCategory = array();
        $k = 0;
        foreach ($aryProductCategory as $key => $value) {
            if ($value['category_parent'] == 0) {
                $aryRootCategory[$key]['category_id'] = $value['category_id'];
                $aryRootCategory[$key]['category_name'] = $value['category_name'];
                $aryRootCategory[$key]['category_name_filter'] = $value['category_name_filter'];
                $arySubCategory[$value['category_id']]['category_id'] = $value['category_id'];
            }
            if ($value['category_parent'] && $value['category_level'] == 1) {
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_id'] = $value['category_id'];
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_name'] = $value['category_name'];
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_name_filter'] = $value['category_name_filter'];
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_total_child'] = $value['category_total_child'];
            }
        }
        $this->assign('aryRootCategory', $aryRootCategory);
        $this->assign('arySubcategory', $arySubCategory);
        $content = $this->getCacheHtmlTemplate('top_menu');
        $this->saveHtmlCache('top_menu', $content);
    }

    public function saveProductMaker() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $aryParam = $this->getAllPostParams();

        $type = $this->getParam('type');

        $parentCategoryId = $aryParam['category_id_hidden'];

        $aryProductMakerName = $aryParam['product_maker_name'];

        $aryOtherProductMaker = $aryParam['other_product_maker'];

        $count = 0;

        $coutInput = count($aryProductMakerName);

        $aryFile = $_FILES['image_logo']['name'];

        $aryError = array();

        $aryResult = array();

        $intOk = 1;

        if ($parentCategoryId == '') {
            $aryError[] = 'Bạn chưa chọn danh mục sản phẩm.';
        }

        if ($parentCategoryId != 0) {

            $this->_objAdminModule->getCategoryById($parentCategoryId, $aryCategory);

            if ($aryCategory[0]['category_total_child'] > 0) {
                $aryError[] = 'Danh mục sản phẩm bạn chọn chưa phải là danh mục cuối cùng.';
            }
        }

        if ($type == 'add') {
            if (isset($aryOtherProductMaker[0]) == false || $aryOtherProductMaker[0] == '') {
                foreach ($aryProductMakerName as $key => $value) {
                    if (trim($value) == '') {
                        $count++;
                    }
                    if (trim($value) != '' && $aryFile[$key] == '') {
                        $aryError[] = 'Bạn chưa chọn ảnh Logo cho hãng sản xuất ' . $value . '.';
                    }
                }
            }
        }

        if ($type == 'add') {
            if ($count == $coutInput) {
                $aryError[] = 'Bạn chưa nhập tên hãng sản xuất.';
            }
        } else {
            if ($aryProductMakerName[0] == '') {
                $aryError[] = 'Bạn chưa nhập tên hãng sản xuất.';
            }
        }

        if ($type == 'add') {
            $flag = $this->checkAllowImage('image_logo');
            if ($flag == false) {
                $aryError[] = 'Bạn chỉ được upload file ảnh (jpg, jpeg, gif, png).';
            }
            $flag = $this->checkFileSizeUpload('image_logo', 1048576);
            if ($flag == false) {
                $aryError[] = 'Dung lượng file Upload không được lớn hơn 1 MB.';
            }
        } else {
            $flag = $this->checkEmptyFile('image_logo');
            if ($flag == false) {
                $flag = $this->checkAllowImage('image_logo');
                if ($flag == false) {
                    $aryError[] = 'Bạn chỉ được upload file ảnh (jpg, jpeg, gif, png).';
                }
                $flag = $this->checkFileSizeUpload('image_logo', 1048576);
                if ($flag == false) {
                    $aryError[] = 'Dung lượng file Upload không được lớn hơn 1 MB.';
                }
            }
        }

        if (count($aryError) > 0) {
            $intOk = -2;
            $strError = join("<br>", $aryError);
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = $strError;
            echo json_encode($aryResult);
            return;
        }


        $imageDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR;

        $imageSmallDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'small' . DIRECTORY_SEPARATOR;

        //main image
        $this->multiUploadFile('image_logo', $imageDir, $resultMainImage, $this->getConfig('img_maker_main_size'));
        //small image
        $this->multiUploadFile('image_logo', $imageSmallDir, $resultSmallImage, $this->getConfig('img_maker_small_size'));

//        $intOk = $this->_objAdminModule->getCategoryById($parentCategoryId, $aryCategory);
//
//        $categoryName = $aryCategory[0]['category_name'];

        if ($type == 'add') {

            if (isset($aryOtherProductMaker[0])) {
                foreach ($aryOtherProductMaker as $key => $value) {
                    $aryProductMakerCategory = array();
                    $aryProductMakerCategory['product_maker_category_maker_id'] = $value;
                    $aryProductMakerCategory['product_maker_category_category_id'] = $parentCategoryId;
                    $intOk = $this->_objAdminModule->insertProductMakerCategory($aryProductMakerCategory);
                }
            }

            if (count($aryProductMakerName) > 0) {
                foreach ($aryProductMakerName as $key => $value) {
                    if (trim($value) != '' && $resultMainImage[$key] != '') {
                        $aryProductMakerInsert = array();
                        $aryProductMakerInsert['product_maker_name'] = $value;
                        $aryProductMakerInsert['product_maker_name_filter'] = $this->filterUnicode($value);
                        $aryProductMakerInsert['product_maker_main_logo'] = $resultMainImage[$key]['image_name'];
                        $aryProductMakerInsert['product_maker_small_logo'] = $resultSmallImage[$key]['image_name'];
                        $intOk = $this->_objAdminModule->insertProductMaker($aryProductMakerInsert, $returnProductMakerId);
                        //insert product maker category for relation
                        $aryProductMakerCategory = array();
                        $aryProductMakerCategory['product_maker_category_maker_id'] = $returnProductMakerId;
                        $aryProductMakerCategory['product_maker_category_category_id'] = $parentCategoryId;
                        $intOk = $this->_objAdminModule->insertProductMakerCategory($aryProductMakerCategory);
                    }
                }
            }
        } else {

            $aryCondition = array(
                array(
                    'keyword' => 'WHERE',
                    'field' => 'product_maker_id',
                    'math' => '=',
                    'value' => $aryParam['product_maker_id']
                )
            );

            foreach ($aryProductMakerName as $key => $value) {

                $aryProductMakerUpdate = array();

                $aryProductMakerUpdate['product_maker_name'] = $value;

                if (isset($resultMainImage[$key]['image_name']) == true && $resultMainImage[$key]['image_name'] != '') {

                    $aryProductMakerUpdate['product_maker_main_logo'] = $resultMainImage[$key]['image_name'];

                    $aryProductMakerUpdate['product_maker_small_logo'] = $resultSmallImage[$key]['image_name'];
                }

                $intOk = $this->_objAdminModule->updateProductMaker($aryCondition, $aryProductMakerUpdate);
            }

            $aryCondition2 = array(
                array(
                    'keyword' => 'WHERE',
                    'field' => 'product_maker_category_id',
                    'math' => '=',
                    'value' => $aryParam['product_maker_category_id']
                )
            );

            $aryMakerCategoryUpdate = array();

            $aryMakerCategoryUpdate['product_maker_category_category_id'] = $parentCategoryId;

            $intOk = $this->_objAdminModule->updateProductMakerCategory($aryCondition2, $aryMakerCategoryUpdate);
        }


        $aryResult['intOk'] = $intOk;

        if ($type == 'add') {
            $aryResult['successMessage'] = 'Hãng sản xuất đã được thêm.';
        } else {
            $aryResult['successMessage'] = 'Hãng sản xuất đã được cập nhật.';
        }
        $aryResult['type'] = $type;
        echo json_encode($aryResult);
    }

    public function saveSubCatInOverlay() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryData = $this->getAllPostParams();
        $arySubName = $aryData['sub_category_name'];
        $parentId = $aryData['cat_id_hidden'];
        $intOk = -2;
        foreach ($arySubName as $key => $value) {
            if (strlen($value) > 0) {
                $aryInsert = array();
                $aryInsert['category_name'] = trim($value);
                $aryInsert['category_parent'] = $parentId;
                $aryInsert['category_level'] = 2;
                $aryInsert['category_name_filter'] = $this->filterUnicode($value);
                $intOk = $this->_objAdminModule->insertCategory($aryInsert);
            }
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        echo json_encode($aryResult);
    }

    public function saveNewsSubCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryData = $this->getAllPostParams();
        $arySubName = $aryData['sub_news_category_name'];
        $parentId = $aryData['cat_news_id_hidden'];
        $intOk = -2;
        foreach ($arySubName as $key => $value) {
            if (strlen($value) > 0) {
                $aryInsert = array();
                $aryInsert['news_category_name'] = trim($value);
                $aryInsert['news_category_parent'] = $parentId;
                $aryInsert['news_category_level'] = 2;
                $aryInsert['news_category_filter'] = $this->filterUnicode($value);
                $intOk = $this->_objAdminModule->insertNewsCategory($aryInsert);
            }
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        echo json_encode($aryResult);
    }

    public function editCategoryById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();

        $ulId = $aryParam['ulId'];

        $categoryId = $aryParam['categoryId'];

        $parentId = $aryParam['parentId'];

        $imageDir = $this->getImageUploadDir('main');

        $imageSmallDir = $this->getImageUploadDir('small');

        $imageLargeDir = $this->getImageUploadDir('large');

        if ($this->checkEmptyFile('edit_cat_image') == false) {
            //main image
            $this->multiUploadFile('edit_cat_image', $imageDir, $resultMainImage, $this->getConfig('img_category_main_size'), $this->filterUnicode($aryParam['categoryName']));
            //small image
            $this->multiUploadFile('edit_cat_image', $imageSmallDir, $resultSmallImage, $this->getConfig('img_category_small_size'), $this->filterUnicode($aryParam['categoryName']));
            //large image
            $this->multiUploadFile('edit_cat_image', $imageLargeDir, $resultLargeImage, $this->getConfig('img_category_lager_size'), $this->filterUnicode($aryParam['categoryName']));
        }

        $aryCatEdit = array();
        $aryCatEdit['category_name'] = $aryParam['categoryName'];
        $aryCatEdit['category_keyword'] = $aryParam['categoryName'] . ',' . $this->removeUnicode($aryParam['categoryName']);
        $aryCatEdit['category_title_header'] = $aryParam['categoryName'];
        $aryCatEdit['category_description'] = $aryParam['categoryName'];
        $aryCatEdit['category_name_filter'] = $this->filterUnicode($aryParam['categoryName']);
        $intOk = $this->_objAdminModule->getCategoryImageByListId($categoryId, $aryCategoryImage);
        if ($this->checkEmptyFile('edit_cat_image') == false) {
            $this->deleteImage($aryCategoryImage[0]['category_main_image'], 'main');
            $this->deleteImage($aryCategoryImage[0]['category_small_image'], 'small');
            $this->deleteImage($aryCategoryImage[0]['category_large_image'], 'large');
            $imageExtension = strtolower(substr($resultMainImage[0]['image_name'], strlen($resultMainImage[0]['image_name']) - 4, 4));
            $newImageName = $this->filterUnicode($aryParam['categoryName']) . $imageExtension;
            rename($imageDir . $resultMainImage[0]['image_name'], $imageDir . $newImageName);
            rename($imageSmallDir . $resultSmallImage[0]['image_name'], $imageSmallDir . $newImageName);
            rename($imageLargeDir . $resultLargeImage[0]['image_name'], $imageLargeDir . $newImageName);
            $aryCatEdit['category_main_image'] = $newImageName;
            $aryCatEdit['category_small_image'] = $newImageName;
            $aryCatEdit['category_large_image'] = $newImageName;
        } else {
            $imageExtension = strtolower(substr($aryCategoryImage[0]['category_main_image'], strlen($aryCategoryImage[0]['category_main_image']) - 4, 4));
            $newImageName = $this->filterUnicode($aryParam['categoryName']) . $imageExtension;
            rename($imageDir . $aryCategoryImage[0]['category_main_image'], $imageDir . $newImageName);
            rename($imageSmallDir . $aryCategoryImage[0]['category_small_image'], $imageSmallDir . $newImageName);
            rename($imageLargeDir . $aryCategoryImage[0]['category_large_image'], $imageLargeDir . $newImageName);
            $aryCatEdit['category_main_image'] = $newImageName;
            $aryCatEdit['category_small_image'] = $newImageName;
            $aryCatEdit['category_large_image'] = $newImageName;
        }

        $config = array(
            array(
                'keyword' => 'WHERE',
                'field' => 'category_id',
                'math' => '=',
                'value' => $categoryId
            )
        );
        $intOk = $this->_objAdminModule->editCatById($aryCatEdit, $config);

        $this->setFlagByCategoryCache($categoryId);

        $this->setFlagRootCategoryCache();

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['ulId'] = $ulId;
        $aryResult['categoryId'] = $categoryId;
        $aryResult['parentId'] = $parentId;
        $aryResult['message'] = _CATEGORY_EDIT_SUCCESS;
        echo json_encode($aryResult);
    }

    public function setFlagByCategoryCache($categoryId) {

        $aryParentCategoryId = $this->_objAdminModule->getCategoryParentPath($categoryId);

        array_push($aryParentCategoryId, $categoryId);

        foreach ($aryParentCategoryId as $key => $value) {

            $this->setFlagCategoryCache($value);
        }
    }

    public function editNewsCategoryById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $aryParam = $this->getAllPostParams();

        $ulId = $aryParam['ulId'];

        $categoryId = $aryParam['categoryId'];

        $parentId = $aryParam['parentId'];

        $aryResult = array();

        $aryCatEdit = array();

        $aryCatEdit['news_category_name'] = $aryParam['categoryName'];

        $aryCatEdit['news_category_filter'] = $this->filterUnicode($aryParam['categoryName']);

        if ($aryParam['categoryName'] == '') {
            $aryResult['intOk'] = -2;
            $aryResult['strError'] = _NEWS_EMPTY_CATEGORY_NAME;
            echo json_encode($aryResult);
            return;
        }

        $config = array(
            array(
                'keyword' => 'WHERE',
                'field' => 'news_category_id',
                'math' => '=',
                'value' => $aryParam['categoryId']
            )
        );
        $intOk = $this->_objAdminModule->editNewsCatById($aryCatEdit, $config);

        $aryFlag = array();

        $aryFlag[] = 'tintuc_home_menu_flag';

        $aryFlag[] = 'tintuc_parent_of_danhmuc_' . $categoryId . '_flag';

        foreach ($aryFlag as $key => $value) {

            $this->setFlagCacheFile($value);
        }
        $aryResult['intOk'] = $intOk;
        $aryResult['ulId'] = $ulId;
        $aryResult['categoryId'] = $categoryId;
        $aryResult['parentId'] = $parentId;
        $aryResult['message'] = _NEWS_EDIT_CATEGORY_SUCCESS;
        echo json_encode($aryResult);
    }

    public function deleteNewsCategoryById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $newsCatId = $this->getParam('catId');
        $ulId = $this->getParam('ulId');
        $parentId = $this->getParam('parentId');
        $intOk = $this->_objAdminModule->getNewsCategory($aryCategory);
        $aryChild = array();
        $aryChild = $this->findNewsChildPathId($aryCategory, $newsCatId);
        array_push($aryChild, $newsCatId);
        $intOk = $this->_objAdminModule->deleteTotalChildOfNewsParent($parentId);

        foreach ($aryChild as $key => $value) {
            $aryUpdate = array();
            $aryUpdate['news_category_del_flag'] = 1;
            $aryConfig = array(
                array(
                    'keyword' => 'WHERE',
                    'field' => 'news_category_id',
                    'math' => '=',
                    'value' => $value
                )
            );
            $intOk = $this->_objAdminModule->deleteNewCategoryById($aryUpdate, $aryConfig);
        }
        if ($intOk == 1) {
            $listCacheFile = array();
            $pattern = 'tintuc_danhmuc_' . $newsCatId . '_*';
            $listCacheFile = $this->searchCacheFile($pattern);
            foreach ($listCacheFile as $key => $value) {
                $this->deleteListCacheFile($value);
            }

            $listCacheFile = array();
            $pattern = 'tintuc_danhmuc_trangchu_*';
            $listCacheFile = $this->searchCacheFile($pattern);
            foreach ($listCacheFile as $key => $value) {
                $this->setFlagCacheToFile($value);
            }

            $listCacheFile = array();
            $pattern = 'tintuc_parent_of_danhmuc_' . $newsCatId . '*';
            $listCacheFile = $this->searchCacheFile($pattern);
            foreach ($listCacheFile as $key => $value) {
                $this->deleteListCacheFile($value);
            }
        }
        if ($intOk == 1) {
            $aryNewsCondition = array();
            $aryNewsCondition['news_del_flag'] = 1;
            $aryNewsConfig = array(
                array(
                    'keyword' => 'WHERE',
                    'field' => 'news_new_category_id',
                    'math' => '=',
                    'value' => $newsCatId
                )
            );
            $intOk2 = $this->_objAdminModule->deleteNewsByNewsCategoryId($aryNewsCondition, $aryNewsConfig);
            if ($intOk2 == 1) {
                $intOk2 = $this->_objAdminModule->getNewsImagesByCategoryId($newsCatId, $aryNewsImages);
                foreach ($aryNewsImages as $key => $value) {
                    $this->deleteImage($value['news_main_image'], 'main');
                    $this->deleteImage($value['news_large_image'], 'large');
                    $this->deleteCacheFile('tintuc_chi_tiet_' . $value['news_id']);
                    $this->deleteCacheFile('tintuc_chi_tiet_' . $value['news_id'] . '_flag');
                }
            }
        }
        $aryFlagFile = array();
        $aryFlagFile[] = 'tintuc_tin_xem_nhieu_nhat_flag';

        $aryFlagFile[] = 'tintuc_tin_moi_nhat_flag';

        $aryFlagFile[] = 'tintuc_home_menu_flag';

        foreach ($aryFlagFile as $key => $value) {

            $this->setFlagCacheFile($value);
        }


        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['parentId'] = $parentId;
        $aryResult['ulId'] = $ulId;
        echo json_encode($aryResult);
    }

    public function saveProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $memberLogin = $this->getSession('login');
        $type = $this->getParam('type');
        $aryPostData = $this->getAllPostParams();
        $aryError = array();
        $arySearchResult = array();
        $arySearchResult = $this->checkExistProduct($aryPostData['product_title'], $aryPostData['product_id']);
        if (isset($arySearchResult[0])) {
            $intOk = -2;
            $aryResult = array();
            $aryResult['intOk'] = $intOk;
            $aryResult['aryError'] = $aryError;
            $aryResult['exist'] = 1;
            $aryResult['product_name_search'] = $aryPostData['product_title'];
            echo json_encode($aryResult);
            return;
        }
        $aryError = $this->validateProduct($aryPostData, $type);
        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult = array();
            $aryResult['intOk'] = $intOk;
            $aryResult['aryError'] = $aryError;
            echo json_encode($aryResult);
            return;
        }
        $imageDir = $this->getImageUploadDir('main');
        $imageSmallDir = $this->getImageUploadDir('small');
        $imageLargelDir = $this->getImageUploadDir('large');
        if ($type == 'edit') {
            $intOk = $this->_objAdminModule->getProductById($aryPostData['product_id'], $aryData);
        }
        if ($this->checkEmptyFile('mainImage') == false) {
            if ($type == 'edit') {
                $mainImage = $aryData[0]['product_main_image'];
                $smallImage = $aryData[0]['product_small_image'];
                $largeImage = $aryData[0]['product_large_image'];
                $flag = $this->deleteImage($mainImage, 'main');
                $flag = $this->deleteImage($smallImage, 'small');
                $flag = $this->deleteImage($largeImage, 'large');
            }
            //main image
            $intOk = $this->multiUploadFile('mainImage', $imageDir, $resultFileUpLoaded, $this->getConfig('img_product_main_size'), $this->filterUnicode($aryPostData['product_title']));
            //small image
            $intOk = $this->multiUploadFile('mainImage', $imageSmallDir, $aryImageSmall, $this->getConfig('img_product_small_size'), $this->filterUnicode($aryPostData['product_title']));
            //large image
            $intOk = $this->multiUploadFile('mainImage', $imageLargelDir, $aryImageLarge, $this->getConfig('img_product_lager_size'), $this->filterUnicode($aryPostData['product_title']));
            $imageMainLocation = $imageDir . $resultFileUpLoaded[0]['image_name'];
            $imageSmallLocation = $imageSmallDir . $aryImageSmall[0]['image_name'];
            $imageLargeLocation = $imageLargelDir . $aryImageLarge[0]['image_name'];
            $this->createWatermark($imageMainLocation);
            $this->createWatermark($imageSmallLocation);
            $this->createWatermark($imageLargeLocation);
        }

        $aryInsert = array();
        $aryInsert['product_title'] = trim($aryPostData['product_title']);
        $aryInsert['product_title_search'] = $this->encodingUnicode(strip_tags($aryPostData['product_title']));
        $aryInsert['product_title_digit'] = strtolower($this->filterUnicode($aryPostData['product_title'][0]));
        $aryInsert['product_title_filter'] = $this->filterUnicode($aryPostData['product_title']);
        $aryInsert['product_content_filter'] = $this->cutString($aryPostData['product_content'], 200);
        $aryInsert['product_type_id'] = $aryPostData['product_type_id'];
        if (trim($aryPostData['product_search_title']) != '') {
            $aryInsert['product_search_title'] = trim($aryPostData['product_search_title']);
        } else {
            $aryInsert['product_search_title'] = trim($aryPostData['product_title']);
        }

        if (trim($aryPostData['product_search_keyword']) != '') {
            $aryInsert['product_search_keyword'] = trim($aryPostData['product_search_keyword']);
        } else {
            $aryInsert['product_search_keyword'] = trim($aryPostData['product_title']);
        }

        if (trim($aryPostData['product_search_description']) != '') {
            $aryInsert['product_search_description'] = trim($aryPostData['product_search_description']);
        } else {
            $aryInsert['product_search_description'] = trim($aryPostData['product_title']);
        }

        if ($aryPostData['product_type_id'] != '' || $aryPostData['product_type_id'] != 0) {
            $aryInsert['product_type_name'] = $aryPostData['product_type_name'];
        }
        $aryInsert['product_category_id'] = $aryPostData['product_category_id_hidden'];

        $aryInsert['product_highlight'] = $aryPostData['product_highlight'];

        $root_page = $this->getRootPage();

        $aryInsert['product_content'] = preg_replace('/\.\.\/\.\./', '', $aryPostData['product_content']);

        //if is add new product
        if ($type == 'add') {
            $aryInsert['product_main_image'] = $resultFileUpLoaded[0]['image_name'];
            $aryInsert['product_small_image'] = $aryImageSmall[0]['image_name'];
            $aryInsert['product_large_image'] = $aryImageLarge[0]['image_name'];
            $aryInsert['product_creator_id'] = $memberLogin['member_id'];
            $aryInsert['product_creator_name'] = $memberLogin['member_login_name'];
            $aryInsert['product_created_date'] = date('Y-m-d H:i:s');
            $aryInsert['product_updater_id'] = $memberLogin['member_id'];
            $aryInsert['product_updated_date'] = date('Y-m-d H:i:s');
            $aryInsert['product_updater_name'] = $memberLogin['member_login_name'];

            $intOk = $this->_objAdminModule->saveProductData($aryInsert, $productId);

            $this->insertProductOtherImage($productId);

            //if is edit product
        } else if ($type == 'edit') {

            if ($this->checkEmptyFile('mainImage') == false) {
                $aryInsert['product_main_image'] = $resultFileUpLoaded[0]['image_name'];
                $aryInsert['product_small_image'] = $aryImageSmall[0]['image_name'];
                $aryInsert['product_large_image'] = $aryImageLarge[0]['image_name'];
            } else {
                $imageExtension = strtolower(substr($aryData[0]['product_main_image'], strlen($aryData[0]['product_main_image']) - 4, 4));
                $newImageName = $this->filterUnicode($aryPostData['product_title']) . date('d-m-Y-H-i-s') . $imageExtension;
                rename($imageDir . $aryData[0]['product_main_image'], $imageDir . $newImageName);
                rename($imageSmallDir . $aryData[0]['product_small_image'], $imageSmallDir . $newImageName);
                rename($imageLargeDir . $aryData[0]['product_large_image'], $imageLargeDir . $newImageName);
                $aryInsert['product_main_image'] = $newImageName;
                $aryInsert['product_small_image'] = $newImageName;
                $aryInsert['product_large_image'] = $newImageName;
            }

            $aryInsert['product_updater_id'] = $memberLogin['member_id'];
            $aryInsert['product_updater_name'] = $memberLogin['member_login_name'];
            $aryInsert['product_updated_date'] = date('Y-m-d H:i:s');
            $aryCondition = array(
                array(
                    'keyword' => 'WHERE',
                    'field' => 'product_id',
                    'math' => '=',
                    'value' => $aryPostData['product_id']
                )
            );

            $intOk = $this->_objAdminModule->updateProduct($aryInsert, $aryCondition);

            $this->insertProductOtherImage($aryPostData['product_id']);

            $productId = $aryPostData['product_id'];
        }

        $categoryId = $aryPostData['product_category_id_hidden'];

        $this->setFlagProductDetailCache($productId);

        $this->setFlagProductByCategoryCache($categoryId);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        if ($type == 'add') {
            $aryResult['message'] = _PRODUCT_CONFIRM_ADD_SUCCESS;
        } elseif ($type == 'edit') {
            $aryResult['message'] = _PRODUCT_UPDATE_SUCCESS;
        }
        $aryResult['type'] = $type;
        header("Content-Type: text/html; charset=UTF-8");
        echo json_encode($aryResult);
    }

    public function checkExistProduct($productName, $productId) {
        $aryError = array();
        $productEncode = $this->encodingUnicode($productName);
        $intOk = $this->_objAdminModule->searchProductExist($productEncode, $aryCheckResult, $productId);
        return $aryCheckResult;
    }

    public function setFlagProductByCategoryCache($categoryId) {

        $aryCatParentId = $this->_objAdminModule->getCategoryParentPath($categoryId);

        array_push($aryCatParentId, $categoryId);

        foreach ($aryCatParentId as $key => $value) {

            $this->setFlagProductCache($value);
        }
    }

    public function updateProductOrderPrice($aryPostData, $aryInsert) {
        $this->_objAdminModule->checkProductOrderExist($aryPostData['product_id'], $aryData);
        if (isset($aryData[0]['product_order_product_id'])) {
            $aryConfig = array(
                array(
                    'keyword' => 'where',
                    'field' => 'product_order_product_id',
                    'math' => '=',
                    'value' => $aryPostData['product_id']
                )
            );

            $aryUpdateData = array();
            if (isset($aryInsert['product_title'])) {
                $aryUpdateData['product_order_product_name'] = $aryInsert['product_title'];
                $aryUpdateData['product_order_product_name_filter'] = $aryInsert['product_title_filter'];
            }
            if (isset($aryInsert['product_price_vnd_in'])) {
                $aryUpdateData['product_order_product_price_in'] = $aryInsert['product_price_vnd_in'];
            }
            if (isset($aryInsert['product_price_vnd'])) {
                $aryUpdateData['product_order_product_price'] = $aryInsert['product_price_vnd'];
                $aryUpdateData['product_order_total_price'] = $aryData[0]['product_order_total_product'] * $aryInsert['product_price_vnd'];
            }
            if (isset($aryInsert['product_category_id'])) {
                $aryUpdateData['product_order_category_id'] = $aryInsert['product_category_id'];
            }
            if (isset($aryInsert['product_category_name'])) {
                $aryUpdateData['product_order_category_name'] = $aryInsert['product_category_name'];
                $aryUpdateData['product_order_category_filter'] = $this->filterUnicode($aryInsert['product_category_name']);
            }
            $intOk = $this->_objAdminModule->updateProductOrder($aryConfig, $aryUpdateData);
            return $intOk;
        }
    }

    public function insertProductOtherImage($productId) {
        $aryPostData = $this->getAllPostParams();
        $aryProductImageTitle = $aryPostData['product_image_title'];
        $imageDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR;
        $imageSmallDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'small' . DIRECTORY_SEPARATOR;
        $imageLargelDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'large' . DIRECTORY_SEPARATOR;
        //main image
        $intOk = $this->multiUploadFile('product_other_image', $imageDir, $resultFileUpLoaded, $this->getConfig('img_other_main_size'));
        //small image
        $intOk = $this->multiUploadFile('product_other_image', $imageSmallDir, $aryImageSmall, $this->getConfig('img_other_small_size'));
        //large image
        $intOk = $this->multiUploadFile('product_other_image', $imageLargelDir, $aryImageLarge, $this->getConfig('img_other_lager_size'));


        if (count($resultFileUpLoaded) > 0) {
            foreach ($resultFileUpLoaded as $key => $value) {
                $aryProductImage = array();
                $aryProductImage['product_image_product_id'] = $productId;
                $aryProductImage['product_image_title'] = $aryProductImageTitle[$key];
                $aryProductImage['product_image_main_image'] = $resultFileUpLoaded[$key]['image_name'];
                $aryProductImage['product_image_small_image'] = $aryImageSmall[$key]['image_name'];
                $aryProductImage['product_image_large_image'] = $aryImageLarge[$key]['image_name'];
                $this->_objAdminModule->insertProductImage($aryProductImage);
            }
        }
    }

    public function resetCategoryAndProductCache($categoryId) {
        $aryCategoryId = $this->_objAdminModule->getCategoryParentPath($categoryId);
        array_push($aryCategoryId, $categoryId);
        foreach ($aryCategoryId as $key => $value) {
            $this->setFlagCategoryCache($value);
            $this->setFlagProductCache($value);
        }
    }

    public function buildHtmlCacheHomeProductType() {

        $aryProuductType = $this->getConfig('product_type');

        $aryProductByType = array();

        foreach ($aryProuductType as $key => $value) {

            $this->_objAdminModule->getProductByType($key, $aryProductByType[$key], $listCategory);
        }

        $this->assign('aryProductByType', $aryProductByType);

        $this->assign('aryProductType', $aryProuductType);

        $content = $this->getCacheHtmlTemplate('home_product_by_type');

        $this->saveHtmlCache('home_product_by_type', $content);
    }

    public function buildHtmlCacheHomeProduct() {

        $this->_objAdminModule->getRootProductCategory($aryRootCategory);

        foreach ($aryRootCategory as $key => $value) {

            $aryCategoryId[] = $value['category_id'];
        }

        foreach ($aryCategoryId as $key => $value) {

            $ary[] = $this->_objAdminModule->getCategoryChildPath($value);

            if (count($ary[$key]) > 0) {

                $strCategory = implode(',', $ary[$key]);
            } else {

                $strCategory = 0;
            }

            $limit = $this->getConfig('limit_product_home');

            $this->_objAdminModule->getProductByListCatId($strCategory, $limit, $aryProduct[$value]);
        }

        $this->assign('aryConfCategory', $aryRootCategory);
        $this->assign('categoryId', 'all');
        $this->assign('aryProduct', $aryProduct);
        $content = $this->getCacheHtmlTemplate('home_product');
        $this->saveHtmlCache('home_product', $content);
    }

    public function validateProduct($aryPostData, $type) {
        $aryError = array();
        $objValidator = new Validator();
        $flag = $objValidator->validateEmpty($aryPostData['product_title']);
        if ($flag == true) {
            $aryError['product_title_error'] = _PRODUCT_EMPTY_NAME;
        }
        if ($type == 'add') {
            $flag = $this->checkEmptyFile('mainImage');
            if ($flag == true) {
                $aryError['product_image_error'] = _PRODUCT_EMPTY_IMAGE;
            } else {
                $flag = $this->checkAllowImage('mainImage');
                if ($flag == false) {
                    $aryError['product_image_error'] = _PRODUCT_ERROR_FORMAT_IMAGE;
                } else {
                    $flag = $this->checkFileSizeUpload('mainImage', 524288);
                    if ($flag == false) {
                        $aryError['product_image_error'] = _PRODUCT_ERROR_FILE_SIZE_IMAGE;
                    }
                }
            }
        } else {
            $flag = $this->checkEmptyFile('mainImage');
            if ($flag == false) {
                $flag = $this->checkAllowImage('mainImage');
                if ($flag == false) {
                    $aryError['product_image_error'] = _PRODUCT_ERROR_FORMAT_IMAGE;
                } else {
                    $flag = $this->checkFileSizeUpload('mainImage', 524288);
                    if ($flag == false) {
                        $aryError['product_image_error'] = _PRODUCT_ERROR_FILE_SIZE_IMAGE;
                    }
                }
            }
        }

        $flag = $objValidator->validateEmpty($aryPostData['product_category_id_hidden']);
        if ($flag == true) {
            $aryError['product_category_id_error'] = _PRODUCT_EMPTY_CATEGORY;
        } else {

            $this->_objAdminModule->getCategoryById($aryPostData['product_category_id_hidden'], $aryCategory);

            if ($aryCategory[0]['category_total_child'] > 0) {

                $aryError['product_category_id_error'] = 'Danh mục sản phẩm bạn chọn chưa phải là danh mục cuối cùng.';
            }
        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_maker_id']);
        if ($flag == true) {
//            $aryError['product_maker_id_error'] = _PRODUCT_EMPTY_MAKER;
        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_price_vnd']);
//        if ($flag == true) {
//            $aryError['product_price_vnd_error'] = _PRODUCT_EMPTY_PRICE;
//        } else {
//            $flag = $objValidator->validateNumber($aryPostData['product_price_vnd']);
//            if ($flag == false) {
//                $aryError['product_price_vnd_error'] = _PRODUCT_ERROR_FORMAT_PRICE;
//            }
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_price_vnd_km']);
//        if ($flag == false) {
//            $flag = $objValidator->validateNumber($aryPostData['product_price_vnd_km']);
//            if ($flag == false) {
//                $aryError['product_price_vnd_km_error'] = _PRODUCT_ERROR_FORMAT_PRICE_KM;
//            }
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_type_id']);
//        if ($flag == true) {
//            $aryError['product_type_id_error'] = _PRODUCT_EMPTY_PRODUCT_TYPE;
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_store_id']);
//        if ($flag == true) {
//            $aryError['product_store_id_error'] = _PRODUCT_EMPTY_STORE;
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_warranty_id']);
//        if ($flag == true) {
//            $aryError['product_warranty_id_error'] = _PRODUCT_EMPTY_WARRANTY;
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_origin_id']);
//        if ($flag == true) {
//            $aryError['product_origin_id_error'] = _PRODUCT_EMPTY_ORIGIN;
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_transportation_id']);
//        if ($flag == true) {
//            $aryError['product_transportation_id_error'] = _PRODUCT_EMPTY_TRANSPORTATION;
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_promotional_from']);
//        if ($flag == false) {
//            $flag = $objValidator->validateDateFormat($aryPostData['product_promotional_from']);
//            if ($flag == false) {
//                $aryError['product_promotional_error'] = _PRODUCT_ERROR_FORMAT_PROMATIONAL_DATE;
//            }
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_promotional_to']);
//        if ($flag == false) {
//            $flag = $objValidator->validateDateFormat($aryPostData['product_promotional_to']);
//            if ($flag == false) {
//                $aryError['product_promotional_error'] = _PRODUCT_ERROR_FORMAT_PROMATIONAL_DATE;
//            }
//        }
//        $flag = $objValidator->validateEmpty($aryPostData['product_highlight']);
//        if ($flag == true) {
//            $aryError['product_highlight_error'] = _PRODUCT_EMPTY_HIGHLIGHT;
//        }
        return $aryError;
    }

    public function saveProductSpecsInfo($aryPostData, $productId) {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $arySelectParam = $aryPostData['cat_select'];
        $aryCheckboxParam = $aryPostData['cat_checkbox'];
        $aryInputParam = $aryPostData['cat_input'];
        $aryAreaParam = $aryPostData['text_area'];
        $aryRadioBox = $aryPostData['cat_radio'];

        //save select box category info
        foreach ($arySelectParam as $key => $value) {
            if ($value != 0) {
                $aryProductSpecs = array();
                $aryProductSpecs['product_specs_product_id'] = $productId;
                $aryProductSpecs['product_specs_specs_name'] = $this->_objAdminModule->getSpecsNameById($value);
                $aryProductSpecs['product_specs_specs_id'] = $value;
                $intOk = $this->_objAdminModule->saveProductSpecs($aryProductSpecs);
            }
        }
        //save check box category info
        foreach ($aryCheckboxParam as $key => $checkBoxValue) {
            if ($checkBoxValue != '') {
                $aryProductSpecs = array();
                $aryProductSpecs['product_specs_product_id'] = $productId;
                $aryProductSpecs['product_specs_specs_name'] = $this->_objAdminModule->getSpecsNameById($checkBoxValue);
                $aryProductSpecs['product_specs_specs_id'] = $checkBoxValue;
                $intOk = $this->_objAdminModule->saveProductSpecs($aryProductSpecs);
            }
        }
        //save radio box category info
        foreach ($aryRadioBox as $key => $radioValue) {
            if ($radioValue != '') {
                $aryProductSpecs = array();
                $aryProductSpecs['product_specs_product_id'] = $productId;
                $aryProductSpecs['product_specs_specs_name'] = $this->_objAdminModule->getSpecsNameById($checkBoxValue);
                $aryProductSpecs['product_specs_specs_id'] = $radioValue;
                $intOk = $this->_objAdminModule->saveProductSpecs($aryProductSpecs);
            }
        }
        //save data by input
        foreach ($aryInputParam as $key => $inputValue) {
            if (trim($inputValue) != '') {
                $aryProductSpecs = array();
                $aryProductSpecs['product_specs_product_id'] = $productId;
                $aryProductSpecs['product_specs_specs_name'] = $inputValue;
                $aryProductSpecs['product_specs_specs_id'] = $key;
                $intOk = $this->_objAdminModule->saveProductSpecs($aryProductSpecs);
            }
        }
        //save data by text area
        foreach ($aryAreaParam as $key => $areaValue) {
            if (trim($areaValue) != '') {
                $aryProductSpecs = array();
                $aryProductSpecs['product_specs_product_id'] = $productId;
                $aryProductSpecs['product_specs_specs_name'] = $areaValue;
                $aryProductSpecs['product_specs_specs_id'] = $key;
                $intOk = $this->_objAdminModule->saveProductSpecs($aryProductSpecs);
            }
        }
    }

    public function getDataForEditProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $productId = $this->getParam('productId');
        $categoryId = $this->getParam('categoryId');
        $aryData = array();
        $intOk = $this->_objAdminModule->getProductById($productId, $aryData);
        $aryParentId = $this->_objAdminModule->getCategoryParentPath($categoryId);
//        print_r($aryData);
        array_push($aryParentId, $categoryId);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['data'] = $aryData[0];
        $aryResult['aryParentId'] = $aryParentId;
        if ($aryData[0]['product_promotional_date_from'] != '0000-00-00 00:00:00') {
            $aryResult['product_promotional_from'] = date('d/m/Y', strtotime($aryData[0]['product_promotional_date_from']));
        } else {
            $aryResult['product_promotional_from'] = '';
        }
        if ($aryData[0]['product_promotional_date_to'] != '0000-00-00 00:00:00') {
            $aryResult['product_promotional_to'] = date('d/m/Y', strtotime($aryData[0]['product_promotional_date_to']));
        } else {
            $aryResult['product_promotional_to'] = '';
        }

        echo json_encode($aryResult);
    }

    public function saveNews() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryData = $this->getAllPostParams();

        $memberLogin = $this->getSession('login');

        $type = $this->getParam('type');

        $aryError = $this->validateNews($aryData, $type);

        $aryResult = array();

        if (count($aryError) > 0) {
            $aryResult['intOk'] = -2;
            $aryResult['messageError'] = _NEWS_VALIDATE_ERROR;
            $aryResult['aryError'] = $aryError;
            echo json_encode($aryResult);
            return;
        }
        $imageDir = $this->getImageUploadDir('main');

        $imageLargelDir = $this->getImageUploadDir('large');

        if ($this->checkEmptyFile('news_main_image') == false) {
            //main image
            $intOk = $this->multiUploadFile('news_main_image', $imageDir, $aryMainImage, $this->getConfig('img_news_main_size'), $this->filterUnicode($aryData['news_title']));
            //large image
            $intOk = $this->multiUploadFile('news_main_image', $imageLargelDir, $aryImageLarge, $this->getConfig('img_news_lager_size'), $this->filterUnicode($aryData['news_title']));
        }

        $aryNewsInsert = array();
        $aryNewsInsert['news_title'] = $this->removeHTML($aryData['news_title']);
        $aryNewsInsert['news_title_filter'] = $this->filterUnicode($this->removeHTML($aryData['news_title']));
        $aryNewsInsert['news_title_digit'] = $aryNewsInsert['news_title_filter'][0];
        $aryNewsInsert['news_title_search'] = $this->encodingUnicode($this->removeHTML($aryData['news_title']));
        $aryNewsInsert['news_title_hash'] = $this->encodePassword($aryData['news_title']);
        if ($aryData['news_new_sub_category_id'] != '') {
            $aryNewsInsert['news_new_category_id'] = $aryData['news_new_sub_category_id'];
        } else {
            $aryNewsInsert['news_new_category_id'] = $aryData['news_new_category_id'];
        }

        if ($aryData['news_type']) {
            $aryNewsInsert['news_type'] = $aryData['news_type'];
        } else {
            $aryNewsInsert['news_type'] = 0;
        }

        if (isset($aryMainImage[0])) {
            $aryNewsInsert['news_main_image'] = $aryMainImage[0]['image_name'];
        }
        if (isset($aryImageLarge[0])) {
            $aryNewsInsert['news_large_image'] = $aryImageLarge[0]['image_name'];
        }
        $subDomain = $this->getSubDomain();
//        $aryNewsInsert['news_content'] = str_replace('src', 'data-src', $aryData['news_content']);
        $aryNewsInsert['news_content'] = str_replace('../../public', $subDomain['img'], $aryData['news_content']);
        $aryNewsInsert['news_content_filter'] = $this->cutString($aryData['news_content']);

        if ($type == 'add') {
            $aryNewsInsert['news_creator_id'] = $memberLogin['member_id'];
            $aryNewsInsert['news_creator_name'] = $memberLogin['member_login_name'];
            $aryNewsInsert['news_created_date'] = date('Y-m-d H:i:s');
            $aryNewsInsert['news_updater_id'] = $memberLogin['member_id'];
            $aryNewsInsert['news_updater_name'] = $memberLogin['member_login_name'];
            $aryNewsInsert['news_updated_date'] = date('Y-m-d H:i:s');
            $intOk = $this->_objAdminModule->saveNewsData($aryNewsInsert);
        } else {
            $aryNewsInsert['news_updater_id'] = $memberLogin['member_id'];
            $aryNewsInsert['news_updater_name'] = $memberLogin['member_login_name'];
            $aryNewsInsert['news_updated_date'] = date('Y-m-d H:i:s');
            $aryCondition = array(
                array(
                    'keyword' => 'WHERE',
                    'field' => 'news_id',
                    'math' => '=',
                    'value' => $aryData['news_id']
                )
            );

            $intOk = $this->_objAdminModule->updateNewsData($aryNewsInsert, $aryCondition);
        }

        $this->setFlagOfSaveEditNews($aryData['news_id']);

        $aryResult['intOk'] = $intOk;
        $aryResult['type'] = $type;
        if ($type == 'add') {
            $aryResult['message'] = _NEWS_SAVE_SUCCESS;
        } else {
            $aryResult['message'] = _NEWS_EDIT_SUCCESS;
        }
        echo json_encode($aryResult);
    }

    public function setFlagOfSaveEditNews($newsId = null) {

        $aryFlagFile = array();

        if (isset($newsId)) {
            $aryFlagFile[] = 'tintuc_chi_tiet_' . $newsId . '_flag';
        }

        $aryFlagFile[] = 'tintuc_tin_xem_nhieu_nhat_flag';

        $aryFlagFile[] = 'tintuc_tin_moi_nhat_flag';

        foreach ($aryFlagFile as $key => $value) {

            $this->setFlagCacheFile($value);
        }

        $pattern = "tintuc_danhmuc*flag.php";

        $aryFile = $this->searchCacheFile($pattern);

        foreach ($aryFile as $key => $value) {

            $this->setFlagCacheToFile($value);
        }
    }

    public function validateNews($aryPostData, $type) {
        $aryError = array();
        $objValidator = new Validator();
        $flag = $objValidator->validateEmpty($aryPostData['news_title']);
        if ($flag == true) {
            $aryError['news_title_error'] = _NEWS_VALIDATE_EMPTY_TITLE;
        }
        if ($type == 'add') {
            $flag = $this->checkEmptyFile('news_main_image');
            if ($flag == true) {
                $aryError['news_main_image_error'] = _NEWS_VALIDATE_EMPTY_IMAGE;
            } else {
                $flag = $this->checkAllowImage('news_main_image');
                if ($flag == false) {
                    $aryError['news_main_image_error'] = _PRODUCT_ERROR_FORMAT_IMAGE;
                } else {
                    $flag = $this->checkFileSizeUpload('news_main_image', 524288);
                    if ($flag == false) {
                        $aryError['news_main_image_error'] = _PRODUCT_ERROR_FILE_SIZE_IMAGE;
                    }
                }
            }
        } else {
            $flag = $this->checkEmptyFile('news_main_image');
            if ($flag == false) {
                $flag = $this->checkAllowImage('news_main_image');
                if ($flag == false) {
                    $aryError['news_main_image_error'] = _PRODUCT_ERROR_FORMAT_IMAGE;
                } else {
                    $flag = $this->checkFileSizeUpload('news_main_image', 524288);
                    if ($flag == false) {
                        $aryError['news_main_image_error'] = _PRODUCT_ERROR_FILE_SIZE_IMAGE;
                    }
                }
            }
        }
        $flag = $objValidator->validateEmpty($aryPostData['news_new_category_id']);
        if ($flag == true) {
            $aryError['news_new_category_id_error'] = _NEWS_VALIDATE_EMPTY_CATEGORY;
        }
//        $flag = $objValidator->validateEmpty($aryPostData['news_new_sub_category_id']);
//        if ($flag == true) {
//            $aryError['news_new_sub_category_id_error'] = _NEWS_VALIDATE_EMPTY_SUB_CATEGORY;
//        }
        $flag = $objValidator->validateEmpty($aryPostData['news_content']);
        if ($flag == true) {
            $aryError['news_content_error'] = _NEWS_VALIDATE_EMPTY_CONTENT;
        }
        return $aryError;
    }

    public function getListProductMaker() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $orderType = $this->getParam('orderType');
        $page = $this->getParam('page');
        $categoryId = $this->getParam('catId');
        $aryConditions = array();
        $aryConditions['record_per_page'] = 100;
        $aryConditions['current_page'] = $page;

        if ($orderType == 'name-up') {
            $aryConditions['field'] = 'product_maker_name';
            $aryConditions['order'] = 'ASC';
        } else if ($orderType == 'name-down') {
            $aryConditions['field'] = 'product_maker_name';
            $aryConditions['order'] = 'DESC';
        } else if ($orderType == 'id-up') {
            $aryConditions['field'] = 'product_maker_id';
            $aryConditions['order'] = 'ASC';
        } else if ($orderType == 'id-down') {
            $aryConditions['field'] = 'product_maker_id';
            $aryConditions['order'] = 'DESC';
        }
        $aryProductMaker = array();

        $aryChildCategory = $this->getChildCat($categoryId);

        if (isset($aryChildCategory[0])) {
            $listCategoryId = implode(',', $aryChildCategory);
        } else {
            $listCategoryId = $categoryId;
        }

        $intOk = $this->_objAdminModule->getListProductMakerData($aryConditions, $listCategoryId, $aryProductMaker);

//        print_r($aryProductMaker);

        $this->setActionJSPaging("AdminController.getListProductMaker('$orderType','$categoryId',");

        $strPaging = $this->AjaxPagination($aryProductMaker['paging']);

        $this->assign('strPaging', $strPaging);

        $this->assign('aryProductMaker', $aryProductMaker['data']);

        $this->assign('categoryId', $categoryId);

        $this->assign('orderType', $orderType);

        $this->assign('page', $page);

        $this->_objAdminModule->getCategory($aryCategory);

        $stringTreeCategory = $this->buildTreeProductCategory($aryCategory, $categoryId);

        $aryResult = array();

        $aryResult['intOk'] = $intOk;

        $aryResult['listProductMaker'] = $this->getViewTemplate('admin/blackadmin', 'product_list_product_maker');

        $aryResult['treeCategory'] = $stringTreeCategory;

        echo json_encode($aryResult);
    }

    public function getProductMakerById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $makerCategoryId = $this->getParam('makerCategoryId');

        $productMakerId = $this->getParam('productMakerId');

        $productCategoryId = $this->getParam('categoryId');

        $productMakerName = $this->getParam('producMakerName');

        $this->assign('productMakerId', $productMakerId);

        $this->assign('categoryId', $productCategoryId);

        $intOk = $this->_objAdminModule->getSubCatByCatId(0, $aryCategory);

        $this->assign('aryCategory', $aryCategory);

        $this->assign('producMakerName', $productMakerName);

        $this->assign('makerCategoryId', $makerCategoryId);

        $aryParentId = $this->_objAdminModule->getCategoryParentPath($productCategoryId);

        array_push($aryParentId, $productCategoryId);

//        print_r($aryParentId);
        $this->assign('aryParentId', $aryParentId);

        $aryResult = array();
        $aryResult['aryParentId'] = $aryParentId;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product_show_edit_maker');

        echo json_encode($aryResult);
    }

    public function buildTreeProductCategory($aryCategory, $categoryId) {

        $aryTreCategory = $this->formatCategories($aryCategory, $categoryId);

        $this->assign('aryTreCategory', $aryTreCategory);

        $strListCategory = $this->getViewTemplate('admin/blackadmin', 'product_maker_list_category');

        return $strListCategory;
    }

    public function buildTreeCatForListProduct($aryCategory, $categoryId) {

        $aryTreCategory = $this->formatCategories($aryCategory, $categoryId);

        $this->assign('aryTreCategory', $aryTreCategory);

        $strListCategory = $this->getViewTemplate('admin/blackadmin', 'product_list_category');

        return $strListCategory;
    }

    public function formatCategories($categories, $parentId) {
        // $navCat stores all children categories
        // of $parentId
        $navCat = array();

        // expand only the categories with the same parent id
        // all other remain compact
        $ids = array();
        foreach ($categories as $category) {
            if ($category['category_parent'] == $parentId) {
                $navCat[] = $category;
            }

            // save the ids for later use
            $ids[$category['category_id']] = $category;
        }

        $tempParentId = $parentId;

        // keep looping until we found the
        // category where the parent id is 0
        while ($tempParentId != 0) {
            $parent = array($ids[$tempParentId]);
            $currentId = $parent[0]['category_id'];

            // get all categories on the same level as the parent
            $tempParentId = $ids[$tempParentId]['category_parent'];
            foreach ($categories as $category) {
                // found one category on the same level as parent
                // put in $parent if it's not already in it
                if ($category['category_parent'] == $tempParentId && !in_array($category, $parent)) {
                    $parent[] = $category;
                }
            }

            // sort the category alphabetically
            array_multisort($parent);

            // merge parent and child
            $n = count($parent);
            $navCat2 = array();
            for ($i = 0; $i < $n; $i++) {
                $navCat2[] = $parent[$i];
                if ($parent[$i]['category_id'] == $currentId) {
                    $navCat2 = array_merge($navCat2, $navCat);
                }
            }

            $navCat = $navCat2;
        }


        return $navCat;
    }

    public function getChildCat($categoryParentId) {
        $aryChildCategory = $this->_objAdminModule->getCategoryChildPath($categoryParentId);
        return $aryChildCategory;
    }

    public function getDataForEditNews() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $newId = $this->getParam('newsId');
        $aryData = array();
        $intOk = $this->_objAdminModule->getNewsById($newId, $aryData);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['data'] = $aryData[0];
        echo json_encode($aryResult);
    }

    public function checkExistMember() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $loginName = $this->getParam('loginName');
        $intOk = $this->_objAdminModule->checkExistedMember($loginName);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        echo json_encode($aryResult);
    }

    public function saveMember() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryData = $this->getAllPostParams();
        $type = $this->getParam('type');
        $objValidate = new Validator();
        $aryError = array();
        $flag = $objValidate->validateEmpty($aryData['member_login_name'], 'Bạn chưa nhập tên đăng nhập.');
        if ($flag == false && $type == 'add') {
            $flag = $this->_objAdminModule->checkExistedMember($aryData['member_login_name']);
            if ($flag == 1) {
                array_push($objValidate->_aryError, 'Tên đăng nhập đã tồn tại. Vui lòng chọn tên khác.');
            }
        }
        $objValidate->validateEmpty($aryData['member_full_name'], 'Bạn chưa nhập họ và tên.');
        $flag = $objValidate->validateEmpty($aryData['member_mail'], 'Bạn chưa nhập email.');
        if ($flag == false) {
            $objValidate->validateMail($aryData['member_mail'], 'Địa chỉ email không đúng.');
        }
        $flag = $objValidate->validateEmpty($aryData['member_phone_number'], 'Bạn chưa nhập số điện thoại.');
        if ($flag == false) {
            $objValidate->validatePhone($aryData['member_phone_number'], 'Số điện thoại không đúng.');
        }
        if ($type == 'add') {
            $flag = $objValidate->validateEmpty($aryData['member_password'], 'Bạn chưa nhập mật khẩu.');
            if ($flag == false) {
                $flag = $objValidate->validateEmpty($aryData['member_password_retype'], 'Bạn chưa nhập lại mật khẩu.');
                if ($flag == false) {
                    $objValidate->validateCompare($aryData['member_password'], $aryData['member_password_retype'], 'Mật khẩu nhập lại không đúng.');
                }
            }
        } else {
            if ($aryData['member_password'] != '') {
                $flag = $objValidate->validateEmpty($aryData['member_password']);
                if ($flag == false) {
                    $flag = $objValidate->validateEmpty($aryData['member_password_retype'], 'Bạn chưa nhập lại mật khẩu.');
                    if ($flag == false) {
                        $objValidate->validateCompare($aryData['member_password'], $aryData['member_password_retype'], 'Mật khẩu nhập lại không đúng.');
                    }
                }
            }
        }

        $intOk = $objValidate->getResultAndErrors($aryError);
        if (isset($aryError[0])) {
            $strError = join("\n", $aryError);
            $aryResult = array();
            $aryResult['intOK'] = $intOk;
            $aryResult['strError'] = $strError;
            echo json_encode($aryResult);
            return;
        }
        $aryInsertMember = array();
        $aryInsertMember['member_login_name'] = $aryData['member_login_name'];
        $aryInsertMember['member_full_name'] = $aryData['member_full_name'];
        $aryInsertMember['member_phone_number'] = $aryData['member_phone_number'];
        $aryInsertMember['member_mail'] = $aryData['member_mail'];
        if ($aryData['member_password'] != '') {
            $aryInsertMember['member_password'] = md5(md5($aryData['member_password']));
        }
        $aryInsertMember['member_address'] = $aryData['member_address'];
        $aryInsertMember['member_yahoo'] = $aryData['member_yahoo'];
        $aryInsertMember['member_yahoo_pass'] = $aryData['member_yahoo_pass'];
        $aryInsertMember['member_skype'] = $aryData['member_skype'];
        if ($aryData['member_is_kd'] != 0) {
            $aryInsertMember['member_is_kd'] = $aryData['member_is_kd'];
        }

        if ($type == 'add') {

            $intOk = $this->_objAdminModule->insertMemember($aryInsertMember, $memberId);
        } else {

            $memberId = $aryData['member_id'];

            $config = array(
                array(
                    'keyword' => 'WHERE',
                    'field' => 'member_id',
                    'math' => '=',
                    'value' => $memberId
                )
            );

            $this->_objAdminModule->deleteMemberPermission($memberId);

            $intOk = $this->_objAdminModule->updateMember($aryInsertMember, $config);
        }

        $aryPermissionProduct = $this->getPostParam('member_permission_product');
        $aryPermisionProductCategory = $this->getPostParam('member_permission_product_category');
        $aryPermissionNews = $this->getPostParam('member_permission_news');
        $aryPermissionNewsCategory = $this->getPostParam('member_permission_news_category');
        $aryPermissionOrder = $this->getPostParam('member_permission_orders');
        $aryPermisionEditOtherData = $this->getPostParam('member_permission_data');
        //them moi
        $aryPermissionProductSpecs = $this->getPostParam('member_permission_product_specs');
        $aryPermissionProductMaker = $this->getPostParam('member_permission_product_maker');
        $aryPermissionProductPrice = $this->getPostParam('member_permission_product_price');
        //insert permission product
        if (isset($aryPermissionProduct[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 1;
            $aryInsertPermission['member_permission_module_name'] = 'Sản phẩm';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermissionProduct);
            $strPermissionName = '';
            foreach ($aryPermissionProduct as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Thêm';
                }
                if ($value == 2) {
                    $strPermissionName.=' Sửa';
                }
                if ($value == 3) {
                    $strPermissionName.=' Xóa';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }

        //insert permission product category
        if (isset($aryPermisionProductCategory[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 2;
            $aryInsertPermission['member_permission_module_name'] = 'Danh mục sản phẩm';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermisionProductCategory);
            $strPermissionName = '';
            foreach ($aryPermisionProductCategory as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Thêm';
                }
                if ($value == 2) {
                    $strPermissionName.=' Sửa';
                }
                if ($value == 3) {
                    $strPermissionName.=' Xóa';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }

        //insert permisson product maker
        if (isset($aryPermissionProductMaker[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 8;
            $aryInsertPermission['member_permission_module_name'] = 'Hãng sản xuất';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermissionProductMaker);
            $strPermissionName = '';
            foreach ($aryPermissionProductMaker as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Thêm';
                }
                if ($value == 2) {
                    $strPermissionName.=' Sửa';
                }
                if ($value == 3) {
                    $strPermissionName.=' Xóa';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }

        //insert permission product specs

        if (isset($aryPermissionProductSpecs[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 7;
            $aryInsertPermission['member_permission_module_name'] = 'Thông số kỹ thuật';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermissionProductSpecs);
            $strPermissionName = '';
            foreach ($aryPermissionProductSpecs as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Thêm';
                }
                if ($value == 2) {
                    $strPermissionName.=' Sửa';
                }
                if ($value == 3) {
                    $strPermissionName.=' Xóa';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }

        //insert permission product price

        if (isset($aryPermissionProductPrice[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 9;
            $aryInsertPermission['member_permission_module_name'] = 'Báo giá';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermissionProductPrice);
            $strPermissionName = '';
            foreach ($aryPermissionProductPrice as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Thêm';
                }
                if ($value == 2) {
                    $strPermissionName.=' Sửa';
                }
                if ($value == 3) {
                    $strPermissionName.=' Xóa';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }

        //insert permission product news
        if (isset($aryPermissionNews[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 3;
            $aryInsertPermission['member_permission_module_name'] = 'Tin tức';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermissionNews);
            $strPermissionName = '';
            foreach ($aryPermissionNews as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Thêm';
                }
                if ($value == 2) {
                    $strPermissionName.=' Sửa';
                }
                if ($value == 3) {
                    $strPermissionName.=' Xóa';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }
        if (isset($aryPermissionNewsCategory[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 4;
            $aryInsertPermission['member_permission_module_name'] = 'Danh mụct tin tức';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermissionNewsCategory);
            $strPermissionName = '';
            foreach ($aryPermissionNewsCategory as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Thêm';
                }
                if ($value == 2) {
                    $strPermissionName.=' Sửa';
                }
                if ($value == 3) {
                    $strPermissionName.=' Xóa';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }
        if (isset($aryPermissionOrder[0])) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 5;
            $aryInsertPermission['member_permission_module_name'] = 'Quản lý đơn hàng';
            $aryInsertPermission['member_permission'] = @implode(',', $aryPermissionOrder);
            $strPermissionName = '';
            foreach ($aryPermissionOrder as $key => $value) {
                if ($value == 1) {
                    $strPermissionName.=' Xử lý đơn hàng';
                }
                if ($value == 2) {
                    $strPermissionName.=' Xóa đơn hàng';
                }
            }
            $aryInsertPermission['member_permission_name'] = $strPermissionName;
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }
        if (isset($aryPermisionEditOtherData)) {
            $aryInsertPermission = array();
            $aryInsertPermission['member_permission_member_id'] = $memberId;
            $aryInsertPermission['member_permission_module'] = 6;
            $aryInsertPermission['member_permission_module_name'] = 'Thao tác dữ liệu';
            $aryInsertPermission['member_permission'] = $aryPermisionEditOtherData;
            if ($aryPermisionEditOtherData == 1) {
                $aryInsertPermission['member_permission_name'] = ' Được sửa dữ liệu của thành viên khác';
            } else if (isset($aryPermisionEditOtherData) == false || $aryPermisionEditOtherData == 0) {
                $aryInsertPermission['member_permission_name'] = ' Không được sửa dữ liệu của thành viên khác.';
            }
            $intOk = $this->_objAdminModule->insertMemberPermisson($aryInsertPermission);
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['type'] = $type;
        echo json_encode($aryResult);
    }

    public function getListMember() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $orderType = $this->getParam('orderType');
        $page = $this->getParam('page');
        $aryConditions = array();
        $aryConditions['record_per_page'] = 100;
        $aryConditions['current_page'] = $page;

        if ($orderType == 'login-name-up') {
            $aryConditions['field'] = 'member_login_name';
            $aryConditions['order'] = 'ASC';
        } else if ($orderType == 'login-name-down') {
            $aryConditions['field'] = 'member_login_name';
            $aryConditions['order'] = 'DESC';
        } else if ($orderType == 'full-name-up') {
            $aryConditions['field'] = 'member_full_name';
            $aryConditions['order'] = 'ASC';
        } else if ($orderType == 'full-name-down') {
            $aryConditions['field'] = 'member_full_name';
            $aryConditions['order'] = 'DESC';
        }

        $intOk = $this->_objAdminModule->getListMember($aryConditions, $aryMember);
        $this->_objAdminModule->getMemberPermission($aryPermission);

        $aryMemberAndPermission = array();

        foreach ($aryMember['data'] as $key => $value) {
            $aryMemberAndPermission[$value['member_id']]['member_id'] = $value['member_id'];
            $aryMemberAndPermission[$value['member_id']]['member_login_name'] = $value['member_login_name'];
            $aryMemberAndPermission[$value['member_id']]['member_full_name'] = $value['member_full_name'];
            $aryMemberAndPermission[$value['member_id']]['member_mail'] = $value['member_mail'];
        }

        foreach ($aryPermission as $key => $value) {
            $aryMemberAndPermission[$value['member_permission_member_id']]['permission'][$value['member_permission_id']]['module_name'] = $value['member_permission_module_name'];
            $aryMemberAndPermission[$value['member_permission_member_id']]['permission'][$value['member_permission_id']]['permission_name'] = $value['member_permission_name'];
        }
//        print_r($aryMemberAndPermission);
        $this->setActionJSPaging("AdminController.getListMember('$orderType',");
        $strPaging = $this->AjaxPagination($aryMember['paging']);
        $this->assign('strPaging', $strPaging);
        $this->assign('aryMember', $aryMemberAndPermission);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['listMember'] = $this->getViewTemplate('admin/blackadmin', 'member_list_member');
        echo json_encode($aryResult);
    }

    public function getCategoryForPermission() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $this->_objAdminModule->getCategory($aryCategory);

        $aryProductCatData = array();

        foreach ($aryCategory as $key => $value) {
            if ($value['category_level'] == 1) {
                $aryProductCatData[$value['category_id']]['category_id'] = $value['category_id'];
                $aryProductCatData[$value['category_id']]['category_name'] = $value['category_name'];
            }
            if ($value['category_level'] == 2) {
                $aryProductCatData[$value['category_parent']]['sub_category'][$value['category_id']]['category_id'] = $value['category_id'];
                $aryProductCatData[$value['category_parent']]['sub_category'][$value['category_id']]['category_name'] = $value['category_name'];
            }
        }

        $intOk = $this->_objAdminModule->getNewsCategory($aryNewsCategory);

        $aryNewsCatData = array();

        foreach ($aryNewsCategory as $key => $value) {
            if ($value['news_category_level'] == 1) {
                $aryNewsCatData[$value['news_category_id']]['news_category_id'] = $value['news_category_id'];
                $aryNewsCatData[$value['news_category_id']]['news_category_name'] = $value['news_category_name'];
            }
            if ($value['news_category_level'] == 2) {
                $aryNewsCatData[$value['news_category_parent']]['sub_category'][$value['news_category_id']]['news_category_id'] = $value['news_category_id'];
                $aryNewsCatData[$value['news_category_parent']]['sub_category'][$value['news_category_id']]['news_category_name'] = $value['news_category_name'];
            }
        }
        $this->assign('aryProductCategory', $aryProductCatData);

        $this->assign('aryNewsCategory', $aryNewsCatData);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['productCategory'] = $this->getViewTemplate('admin/blackadmin', 'product-category-for-permission');
        $aryResult['newsCategory'] = $this->getViewTemplate('admin/blackadmin', 'news_category_for_permission');
        echo json_encode($aryResult);
    }

    public function getMemberById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $memberId = $this->getParam('memberId');
        $intOk = $this->_objAdminModule->getMemmberById($memberId, $aryMember);
        $this->_objAdminModule->getPermissionByMemberId($memberId, $aryMemberPermission);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['memberData'] = $aryMember[0];
        if (isset($aryMemberPermission[0])) {
            foreach ($aryMemberPermission as $key => $value) {
                if ($value['member_permission_module'] == 1) {
                    $aryResult['permissionProduct'] = $value['member_permission'];
                }
                if ($value['member_permission_module'] == 2) {
                    $aryResult['permissionProductCategory'] = $value['member_permission'];
                }
                if ($value['member_permission_module'] == 3) {
                    $aryResult['permissionNews'] = $value['member_permission'];
                }
                if ($value['member_permission_module'] == 4) {
                    $aryResult['permissionNewsCategory'] = $value['member_permission'];
                }
                if ($value['member_permission_module'] == 5) {
                    $aryResult['permissionOrder'] = $value['member_permission'];
                }
                if ($value['member_permission_module'] == 6) {
                    $aryResult['permissionEditData'] = $value['member_permission'];
                }
            }
        }
        echo json_encode($aryResult);
    }

    public function checkExistProductSubCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $intOk = 1;
        $categoryId = $this->getParam('categoryId');
        $selectId = $this->getParam('selectId');
        $nextCatId = $this->getParam('nextCatId');
        $type = $this->getParam('type');
        $nextSelectId = $selectId + 1;
        if ($categoryId == 0) {
            $intOk = -2;
        }
        $aryCategory = array();
        if ($intOk == 1) {
            $intOk = $this->_objAdminModule->getSubCatByCatId($categoryId, $aryCategory);
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['selectId'] = $nextSelectId;
        $aryResult['nextCatId'] = $nextCatId;
        $aryResult['aryCategory'] = $aryCategory;
        $aryResult['type'] = $type;
        echo json_encode($aryResult);
    }

    public function checkExistSpecs() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;

        $spectId = $this->getParam('specsId');

        $selectId = $this->getParam('selectId');

        $nextSpecsId = $this->getParam('nextSpecsId');

        $nextSelectId = $selectId + 1;

        if ($spectId == 0) {
            $intOk = -2;
        }

        $arySpecs = array();

        if ($intOk == 1) {

            $intOk = $this->_objAdminModule->getSpecsById($spectId, $arySpecsInPutType);

            $intOk = $this->_objAdminModule->getSubSpecsBySpecsId($spectId, $arySpecs);
        }

        $specInputType = $arySpecsInPutType[0]['specs_input_type'];

        $this->assign('specInputType', $specInputType);

        $this->assign('selectId', $selectId);

        $this->assign('spectId', $spectId);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['selectId'] = $nextSelectId;
        $aryResult['nextSpecsId'] = $nextSpecsId;
        $aryResult['arySpecs'] = $arySpecs;
        $aryResult['specInputType'] = $specInputType;
        $aryResult['specsInputItem'] = $this->getViewTemplate('admin/blackadmin', 'product_specs_input_item');
        echo json_encode($aryResult);
    }

    public function selectProductSpecs() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $categoryId = $this->getParam('categoryId');

        $productId = $this->getPostParam('product_id');

        $arySubCatInfoId = array();

        $arySpecsName = array();

        if ($productId != '' && is_numeric($productId)) {
            $this->_objAdminModule->getSpecsByProductId($productId, $aryProductSpecs);
            foreach ($aryProductSpecs as $key => $value) {
                $arySubCatInfoId[] = $value['product_specs_specs_id'];
                $arySpecsName[$value['product_specs_specs_id']] = $value['product_specs_specs_name'];
            }
            $this->assign('arySpecsName', $arySpecsName);
            $this->assign('arySubCatInfoId', $arySubCatInfoId);
        }

        $intOk = $this->_objAdminModule->selectSpecsByCategoryId($categoryId, $arySpecs);

        $aryTreeSpecs = array();

        foreach ($arySpecs as $key => $value) {
            if ($value['specs_level'] == 0) {
                $aryTreeSpecs[$value['specs_id']]['category_info_id'] = $value['specs_id'];
                $aryTreeSpecs[$value['specs_id']]['category_info_name'] = $value['specs_name'];
            }
            if ($value['specs_level'] == 1) {
                $aryTreeSpecs[$value['specs_parent']]['sub_category_info'][$value['specs_id']]['category_info_id'] = $value['specs_id'];
                $aryTreeSpecs[$value['specs_parent']]['sub_category_info'][$value['specs_id']]['category_info_name'] = $value['specs_name'];
                $aryTreeSpecs[$value['specs_parent']]['sub_category_info'][$value['specs_id']]['category_info_type'] = $value['specs_input_type'];
            }
            if ($value['specs_level'] == 2) {
                $root = $this->_objAdminModule->getSecsParentPath($value['specs_id']);
                $aryTreeSpecs[$root[0]]['sub_category_info'][$value['specs_parent']]['cat_info_level3'][$value['specs_id']]['category_info_id'] = $value['specs_id'];
                $aryTreeSpecs[$root[0]]['sub_category_info'][$value['specs_parent']]['cat_info_level3'][$value['specs_id']]['category_info_name'] = $value['specs_name'];
            }
        }

//        print_r($aryTreeSpecs);

        $this->assign('aryCategory', $aryTreeSpecs);

        $aryResult = array();

        $aryResult['intOk'] = $intOk;

        $aryResult['listSpecs'] = $this->getViewTemplate('admin/blackadmin', 'product_list_specs_for_add');

        echo json_encode($aryResult);
    }

    public function deleteCategoryById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $categoryId = $this->getParam('catId');

        $ulId = $this->getParam('ulId');

        $parentCatId = $this->getParam('parentId');

        $intOk = $this->_objAdminModule->deleteTotalChildOfParent($parentCatId);

        $aryChildCat = $this->_objAdminModule->getCategoryChildPath($categoryId);

        if (isset($aryChildCat[0]) == false) {

            $aryChildCat[] = $categoryId;
        } else {

            array_push($aryChildCat, $categoryId);
        }

        $listChildId = implode(',', $aryChildCat);

        $intOk = $this->_objAdminModule->getCategoryImageByListId($listChildId, $aryCategoryImage);

        foreach ($aryCategoryImage as $key => $value) {
            $this->deleteImage($value['category_main_image'], 'main');
            $this->deleteImage($value['category_small_image'], 'small');
            $this->deleteImage($value['category_large_image'], 'large');
        }

        $aryCatUpdate = array('category_del_flag' => 1);

        $aryProductUpdate = array('product_del_flag' => 1);

        foreach ($aryChildCat as $key => $value) {

            //xoa tat ca san pham thuoc danh muc do va danh muc con cua no

            $aryProductConditions = array(
                array(
                    'keyword' => 'where',
                    'field' => 'product_category_id',
                    'math' => '=',
                    'value' => $value
                )
            );

            $intOk = $this->_objAdminModule->deleteProductByCatId($aryProductUpdate, $aryProductConditions);

            //xoa tat ca nhung danh muc con thuoc danh muc muon xoa
            $aryCatConditions = array(
                array(
                    'keyword' => 'where',
                    'field' => 'category_id',
                    'math' => '=',
                    'value' => $value
                )
            );

            $intOk = $this->_objAdminModule->deleteCategoryById($aryCatUpdate, $aryCatConditions);
        }

        $this->setFlagProductCache($categoryId);

        $this->setFlagCategoryCache($categoryId);

        $this->setFlagProductByCategoryCache($parentCatId);

        $this->setFlagByCategoryCache($parentCatId);

        $this->setFlagRootCategoryCache();

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['ulId'] = $ulId;
        $aryResult['parentId'] = $parentCatId;
        $aryResult['message'] = _CATEGORY_DELETE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function orderProductCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $strLiId = $this->getParam('strLiId');
        $aryLiId = explode(",", $strLiId);
        $aryCategoryId = array();
        foreach ($aryLiId as $key => $value) {
            if ($value != '') {
                $aryCategoryId[] = substr($value, 7);
            }
        }
        $order = 0;
        foreach ($aryCategoryId as $key => $value) {
            $aryConditions = array(
                array(
                    'keyword' => 'where',
                    'field' => 'category_id',
                    'math' => '=',
                    'value' => $value
                )
            );

            $aryUpdate = array('category_order' => $order);

            $intOk = $this->_objAdminModule->updateOrderProductCategory($aryUpdate, $aryConditions);

            $order++;

            $this->setFlagCategoryCache($value);
        }

        $this->setFlagRootCategoryCache();
    }

    public function orderNewsCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $strLiId = $this->getParam('strLiId');
        $aryLiId = explode(",", $strLiId);
        $aryCategoryId = array();
        foreach ($aryLiId as $key => $value) {
            if ($value != '') {
                $aryCategoryId[] = substr($value, 8);
            }
        }
        $order = 0;
        foreach ($aryCategoryId as $key => $value) {

            $aryConditions = array(
                array(
                    'keyword' => 'where',
                    'field' => 'news_category_id',
                    'math' => '=',
                    'value' => $value
                )
            );

            $aryUpdate = array('news_category_order' => $order);

            $intOk = $this->_objAdminModule->updateOrderNewsCategory($aryUpdate, $aryConditions);

            $order++;
        }
    }

    public function getProductOrder() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $type = $this->getParam('type');

        $order = $this->getParam('order');

        switch ($order) {
            case 1:
                $orderBy = 'ASC';
                break;
            case 2:
                $orderBy = 'DESC';
                break;
        }

        $page = $this->getParam('page');

        $aryConditions = array();

        $aryConditions['type'] = $type;

        $aryConditions['current_page'] = $page;

        $aryConditions['record_per_page'] = 10;

        $aryConditions['order_by'] = $orderBy;

        $intOk = $this->_objAdminModule->getProductOrderDetail($aryConditions, $aryOrderDetail);

        foreach ($aryOrderDetail['data'] as $key => $value) {

            $aryDetailId[] = $value['order_detail_id'];
        }

        $strDetailId = implode(",", $aryDetailId);

        if ($strDetailId != '') {

            $intOk = $this->_objAdminModule->getProductOrderByDetailId($strDetailId, $aryProductOrder);
        }

        $this->setActionJSPaging("AdminController.getProductOrder('$type','$order',");

        $strPaging = $this->AjaxPagination($aryOrderDetail['paging']);

        $this->assign('aryOrderDetail', $aryOrderDetail['data']);

        $this->assign('strPaging', $strPaging);

        $this->assign('aryProductOrder', $aryProductOrder);

        $this->assign('type', $type);

        $this->assign('page', $page);

        $this->assign('order', $order);

        $aryResult = array();

        $aryResult['intOk'] = $intOk;

        $aryResult['orderContent'] = $this->getViewTemplate('admin/blackadmin', 'order_list_order_detail');

        echo json_encode($aryResult);
    }

    public function viewDetailOrder() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $detailId = $this->getParam('orderDetailId');
        $type = $this->getParam('type');
        $intOk = $this->_objAdminModule->getOrderDetailById($detailId, $aryOrderDetail);
        $intOk = $this->_objAdminModule->getProductOrderByDetailId($detailId, $aryProductOrder);
        $this->assign('aryProductOrder', $aryProductOrder);
        foreach ($aryProductOrder as $key => $value) {
            $aryProductId[] = $value['product_order_product_id'];
        }
        $strProductId = implode(",", $aryProductId);
        $this->assign('strProductId', $strProductId);
        $this->assign('aryOrderDetail', $aryOrderDetail[0]);
        $this->assign('detailId', $detailId);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['orderDetailContent'] = $this->getViewTemplate('admin/blackadmin', 'order_view_detail_order');
        echo json_encode($aryResult);
    }

    public function getProductOrderByCustomerId() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $customerId = $this->getParam('customerId');
        $intOk = $this->_objAdminModule->getProductOrderByDetailId($customerId, $aryProductOrder);
        $this->assign('aryProductOrder', $aryProductOrder);
        $this->assign('customerId', $customerId);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['productContent'] = $this->getViewTemplate('admin/blackadmin', 'order_list_product_edit');
        echo json_encode($aryResult);
    }

    public function updateStatusOrder() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $detailId = $this->getParam('detailId');
        $statusType = $this->getParam('statusType');
        $orderComment = $this->getPostParam('orderComment');
        $aryCreator = $this->getSession('login');
        $aryOrderUpdate = array();
        $aryOrderUpdate['order_detail_is_process'] = $statusType;
        $aryOrderUpdate['order_detail_comment'] = $orderComment;
        $aryOrderUpdate['order_detail_process_date'] = date('Y-m-d H:i:s');
        $aryOrderUpdate['order_detail_last_upate_date'] = date('Y-m-d H:i:s');
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'order_detail_id',
                'math' => '=',
                'value' => $detailId
            )
        );

        $intOk = $this->_objAdminModule->updateStatusOrder($aryOrderUpdate, $aryConfig);

        $aryProductOrderUpdate = array();
        $aryProductOrderUpdate['product_order_product_customer_id'] = $productCustomerId;
        $aryProductOrderUpdate['product_order_active'] = 1; //da xac nhan thanh toan
        $aryProductOrderUpdate['product_order_process_date'] = date('Y-m-d H:i:s');
        $aryProductOrderUpdate['product_order_creator_id'] = $aryCreator['member_id'];
        $aryProductOrderUpdate['product_order_creator_name'] = $aryCreator['member_full_name'];
        $aryProductOrderUpdate['product_order_last_update_date'] = date('Y-m-d H:i:s');
        $aryProductOrderConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'product_order_detail_id',
                'value' => $detailId,
                'math' => '='
            )
        );

        $intOk = $this->_objAdminModule->updateStatusOrderActive($aryProductOrderConfig, $aryProductOrderUpdate);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _ORDER_PROCESS_SUCCESS;
        $aryResult['status_type'] = $statusType;
        $aryResult['order_detail_id'] = $detailId;
        echo json_encode($aryResult);
    }

    public function deleteOrder() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $orderId = $this->getParam('orderId');
        $aryDelete = array();
        $aryDelete['order_detail_del_flag'] = 1;
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'order_detail_id',
                'math' => '=',
                'value' => $orderId
            )
        );

        $intOk = $this->_objAdminModule->deleteOrderById($aryDelete, $aryConfig);
        if ($intOk == 1) {
            $aryDeleteProductOrder = array();
            $aryDeleteProductOrder['product_order_del_flag'] = 1;
            $aryConfig = array(
                array(
                    'keyword' => 'where',
                    'field' => 'product_order_detail_id',
                    'math' => '=',
                    'value' => $orderId
                )
            );
            $intOk = $this->_objAdminModule->deleteProductOrderByOrderId($aryDeleteProductOrder, $aryConfig);
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _ORDER_DELETE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function deleteProductOrder() {
        $orderId = $this->getParam('orderId');
        $customerId = $this->getParam('customerId');
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'product_order_id',
                'value' => $orderId,
                'math' => '='
            )
        );

        $aryData = array();
        $aryData['product_order_del_flag'] = 1;
        $intOk = $this->_objAdminModule->deleteProductOrderByOrderId($aryData, $aryConfig);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['customerId'] = $customerId;
        echo json_encode($aryResult);
    }

    public function searchProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;

        $aryParam = $this->getAllPostParams();

        $productName = $aryParam['search_product_name'];

        $parentCategory = $aryParam['search_category_id'];

        if ($productName == '') {

            $strError = _SEARCH_EMPTY_KEYWORD;

            $intOk = -2;
        }

        if ($intOk == 1) {

            $aryChildCategory = array();
            if ($parentCategory != 0) {
                $aryChildCategory = $this->_objAdminModule->getCategoryChildPath($parentCategory);
                array_push($aryChildCategory, $parentCategory);
            }
            if (isset($aryChildCategory[0])) {
                $listCatId = implode(",", $aryChildCategory);
            }
            $orderType = $this->getParam('orderType');
            $page = $this->getParam('page');
            $aryConditions = array();
            $aryConditions['product_name'] = $this->encodingUnicode(trim(strip_tags($productName)));
            $aryConditions['record_per_page'] = $this->getConfig('product_per_page');
            $aryConditions['current_page'] = $page;

            if ($orderType == 'date-up') {
                $aryConditions['field'] = 'product_updated_date';
                $aryConditions['order'] = 'ASC';
            } else if ($orderType == 'date-down') {
                $aryConditions['field'] = 'product_updated_date';
                $aryConditions['order'] = 'DESC';
            } else if ($orderType == 'price-up') {
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'ASC';
            } else if ($orderType == 'price-down') {
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'DESC';
            } else if ($orderType == 'id-down') {
                $aryConditions['field'] = 'product_id';
                $aryConditions['order'] = 'DESC';
            } else if ($orderType == 'id-up') {
                $aryConditions['field'] = 'product_id';
                $aryConditions['order'] = 'ASC';
            }


            $intOk = $this->_objAdminModule->searchProductData($aryConditions, $listCatId, $aryProduct);

            $this->setActionJSPaging("AdminController.searchProduct('$orderType',");

            $strPaging = $this->AjaxPagination($aryProduct['paging']);

            $this->assign('perProductAdd', $aryParam['perProductAdd']);
            $this->assign('perProductEdit', $aryParam['perProductEdit']);
            $this->assign('perProductDelete', $aryParam['perProductDelete']);
            $this->assign('isMaster', $aryParam['isMaster']);

            $this->assign('orderType', $orderType);

            $this->assign('page', $page);

            $this->assign('strPaging', $strPaging);

            $this->assign('aryProduct', $aryProduct['data']);
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['strError'] = $strError;
        $aryResult['searchContent'] = $this->getViewTemplate('admin/blackadmin', 'product_search_result');
        echo json_encode($aryResult);
    }

    public function saveSlider() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;

        $aryResult = array();

        $aryPostParam = $this->getAllPostParams();

        $arySliderTitle = $aryPostParam['slider_title'];

        $arySliderLink = $aryPostParam['slider_link'];

        $aryFile = $_FILES['slider_image']['name'];

        $aryError = array();

        $countTitle = count($arySliderTitle);

        $count = 0;

        foreach ($arySliderTitle as $key => $value) {
            if ($value == '') {
                $count++;
            } else {
                if ($arySliderLink[$key] == '' && $aryFile[$key] != '') {
                    $aryError[] = 'Bạn chưa nhập link cho slider ' . $value;
                }
                if ($aryFile[$key] == '' && $arySliderLink[$key] != '') {
                    $aryError[] = 'Bạn chưa chọn hình ảnh cho slider ' . $value;
                }
                if ($arySliderLink[$key] == '' && $aryFile[$key] == '') {
                    $aryError[] = 'Bạn chưa nhập link và hình ảnh cho slider ' . $value;
                }
            }
        }

        if ($countTitle == $count) {
            $aryError[] = 'Bạn chưa nhập dữ liệu.';
        }

        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }

        if ($intOk == 1) {

            $imageDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'slider' . DIRECTORY_SEPARATOR;
            $imageThumbnailDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'slider' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR;
            //main image
            $this->multiUploadFile('slider_image', $imageDir, $resultMainImage, $this->getConfig('image_slider_size'));
            $this->multiUploadFile('slider_image', $imageThumbnailDir, $resultMainImage, $this->getConfig('image_slider_thumbnail_size'));

            foreach ($arySliderTitle as $key => $value) {
                if ($value != '' && $arySliderLink[$key] != '' && $aryFile[$key] != '') {
                    $arySlider = array();
                    $arySlider['slider_title'] = $value;
                    $arySlider['slider_link'] = $arySliderLink[$key];
                    $arySlider['slider_image'] = $resultMainImage[$key]['image_name'];
                    $intOk = $this->_objAdminModule->insertSlider($arySlider);
                }
            }
        }

        $aryData = array('0' => 1);

        $this->buildSqlCache('flag_slider_cache', $aryData);

        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _SLIDER_SAVE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function getListSlider() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $type = $this->getParam('type');
        $page = $this->getParam('page');
        $aryConditions = array();
        $aryConditions['current_page'] = $page;
        $aryConditions['record_per_page'] = $this->getConfig('product_per_page');
        $aryConditions['slider_type'] = $type;
        $intOk = $this->_objAdminModule->getSlider($aryConditions, $aryData);
        $this->assign('arySlider', $aryData['data']);
        $this->setActionJSPaging("AdminController.getSlider('$type',");
        $strPaging = $this->AjaxPagination($aryData['paging']);
        $this->assign('strPaging', $strPaging);
        $this->assign('type', $type);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['listSlider'] = $this->getViewTemplate('admin/blackadmin', 'slider_list_slider');
        echo json_encode($aryResult);
    }

    public function editSliderById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;

        $sliderId = $this->getParam('sliderId');

        $aryPostParam = $this->getAllPostParams();

        $aryError = array();

        $aryResult = array();

        if ($aryPostParam['slider_title'] == '') {
            $aryError[] = 'Bạn chưa nhập tiêu đề cho slider';
        }
        if ($aryPostParam['slider_link'] == '') {
            $aryError[] = 'Bạn chưa nhập link cho slider';
        }

        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }


        $aryUpdateSlider = array();

        $aryUpdateSlider['slider_title'] = $aryPostParam['slider_title'];

        $aryUpdateSlider['slider_link'] = $aryPostParam['slider_link'];

        $imageDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'slider' . DIRECTORY_SEPARATOR;

        $imageThumbnailDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'slider' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR;

        if ($this->checkEmptyFile('slider_image') == false) {
            $this->multiUploadFile('slider_image', $imageDir, $resultMainImage, $this->getConfig('image_slider_size'));
            $this->multiUploadFile('slider_image', $imageThumbnailDir, $resultThumbImage, $this->getConfig('image_slider_thumbnail_size'));
        }
        $intOk = $this->_objAdminModule->getSliderById($sliderId, $arySlider);

        if ($this->checkEmptyFile('slider_image') == false) {

            unlink($imageDir . $arySlider[0]['slider_image']);

            unlink($imageThumbnailDir . $arySlider[0]['slider_image']);

            $imageExtension = strtolower(substr($resultMainImage[0]['image_name'], strlen($resultMainImage[0]['image_name']) - 4, 4));

            $newImageName = $this->filterUnicode($aryPostParam['slider_title']) . $imageExtension;

            rename($imageDir . $resultMainImage[0]['image_name'], $imageDir . $newImageName);

            rename($imageThumbnailDir . $resultThumbImage[0]['image_name'], $imageThumbnailDir . $newImageName);

            $aryUpdateSlider['slider_image'] = $newImageName;
        } else {

            $imageExtension = strtolower(substr($arySlider[0]['slider_image'], strlen($arySlider[0]['slider_image']) - 4, 4));

            $newImageName = $this->filterUnicode($aryPostParam['slider_title']) . $imageExtension;

            rename($imageDir . $arySlider[0]['slider_image'], $imageDir . $newImageName);

            rename($imageThumbnailDir . $arySlider[0]['slider_image'], $imageThumbnailDir . $newImageName);

            $aryUpdateSlider['slider_image'] = $newImageName;
        }

        $aryUpdateSlider['slider_del_flag'] = 0;

        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'slider_id',
                'math' => '=',
                'value' => $sliderId
            )
        );

        $intOk = $this->_objAdminModule->updateSlider($aryUpdateSlider, $aryConfig);


        $aryData = array('0' => 1);

        $this->buildSqlCache('flag_slider_cache', $aryData);

        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _SLIDER_EDIT_SUCCESS;
        echo json_encode($aryResult);
    }

    public function deleteSlider() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $sliderId = $this->getParam('sliderId');

        $page = $this->getParam('page');

        $aryDelete = array();

        $aryDelete['slider_del_flag'] = 1;

        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'slider_id',
                'math' => '=',
                'value' => $sliderId
            )
        );
        $intOk = $this->_objAdminModule->deleteSlider($aryDelete, $aryConfig);

        if ($intOk == 1) {
            $aryConditions = array();
            $aryConditions['current_page'] = 1;
            $aryConditions['record_per_page'] = 5;
            $aryConditions['slider_type'] = 'active';
            $this->_objAdminModule->getSlider($aryConditions, $aryData);
            if ($page < $aryData['paging']['total_page']) {
                $returnPage = $page;
            } else {
                $returnPage = $aryData['paging']['total_page'];
            }
        }
        $aryData = array('0' => 1);

        $this->buildSqlCache('flag_slider_cache', $aryData);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _SLIDER_DELETE_SUCCESS;
        $aryResult['returnPage'] = $returnPage;
        echo json_encode($aryResult);
    }

    public function logout() {
        if ($this->hasCookie('userId')) {
            $this->clearCookie('userId');
        }
        $this->clearSession('login');
        $this->redirectURL($this->getRootPage() . '/quanly/');
    }

    //be gin news

    public function getListNews() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $orderType = $this->getParam('orderType');
        $page = $this->getParam('page');
        $categoryId = $this->getParam('newCatId');
        $aryConditions = array();
        $aryConditions['record_per_page'] = $this->getConfig('news_limit');
        $aryConditions['current_page'] = $page;

        if ($orderType == 'date-up') {
            $aryConditions['field'] = 'news_updated_date';
            $aryConditions['order'] = 'ASC';
        } else if ($orderType == 'date-down') {
            $aryConditions['field'] = 'news_updated_date';
            $aryConditions['order'] = 'DESC';
        }
        $aryNewsCategory = array();
        $aryNewsSubCategory = array();
        $aryNewsData = array();
        $intOk = $this->_objAdminModule->getNewsCategory($aryNewsCategory);
        if ($categoryId != 0) {
            $aryNewsParent = $this->findNewsParentPath($aryNewsCategory, $categoryId);
            $aryChildPath = $this->findNewsChildPathId($aryNewsCategory, $categoryId);
            array_push($aryChildPath, $categoryId);
            $listCatId = implode(",", $aryChildPath);
            $aryConditions['news_list_category_id'] = $listCatId;
        }
        $aryCategory = array();
        $arySubCategory = array();
        foreach ($aryNewsCategory as $category) {
            if ($category['news_category_level'] == 0) {
                $aryCategory[] = $category;
            }
            if ($category['news_category_level'] == 1) {
                $arySubCategory[] = $category;
            }
        }

        $intOk = $this->_objAdminModule->getNews($aryConditions, $aryNewsData);

        $this->setActionJSPaging("AdminController.getListNews('$orderType','$categoryId',");
        $strPaging = $this->AjaxPagination($aryNewsData['paging']);
        $this->assign('strPaging', $strPaging);
        $this->assign('aryNewsData', $aryNewsData['data']);
        $this->assign('aryNewsSubCategory', $arySubCategory);
        $this->assign('aryNewsCategory', $aryCategory);
        $this->assign('aryNewsParent', $aryNewsParent);
        $this->assign('categoryId', $categoryId);
        $this->assign('orderType', $orderType);
        $this->assign('page', $page);
        $aryPostParam = $this->getAllPostParams();
        $this->assign('perNewsAdd', $aryPostParam['perNewsAdd']);
        $this->assign('perNewsEdit', $aryPostParam['perNewsEdit']);
        $this->assign('perNewsDelete', $aryPostParam['perNewsDelete']);
        $this->assign('isMaster', $aryPostParam['isMaster']);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['listNews'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-news');
        $aryResult['strListNewsSubCat'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-news-sub-cat-hidden');
        $aryResult['listNewsCategory'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-news-left-category');
        $aryResult['jsonNewsCategory'] = $aryCategory;
        echo json_encode($aryResult);
    }

    public function findNewsParentPath($aryData, $subCatId) {
        $aryParent = array();
        foreach ($aryData as $value) {
            if ($value['news_category_id'] == $subCatId) {
                if ($value['news_category_parent'] != 0) {
                    $aryParent[] = $value;
                    $aryParent = array_merge($this->findNewsParentPath($aryData, $value['news_category_parent']), $aryParent);
                } else {
                    $aryParent[] = $value;
                }
            }
        }
        return $aryParent;
    }

    public function findNewsChildPathId($aryData, $newsCatId) {
        $aryChild = array();
        foreach ($aryData as $key => $value) {
            if ($value['news_category_parent'] == $newsCatId) {
                $aryChild[] = $value['news_category_id'];
                $aryChild = array_merge($this->findNewsChildPathId($aryData, $value['news_category_id']), $aryChild);
            }
        }
        return $aryChild;
    }

    public function getListNewsCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $aryNewsCategory = array();
        $parentCategoryId = $this->getParam('parentCatId');
        $ulId = $this->getParam('ulId');
        $nextUlId = $ulId + 1;
        $intOk = $this->_objAdminModule->getNewsCategory($aryNewsCategory, $parentCategoryId);
        if ($parentCategoryId != 0) {
            $this->_objAdminModule->getNewsCategoryById($parentCategoryId, $aryCategoryData);
            $this->assign('aryCategoryData', $aryCategoryData[0]);
        }
        $this->assign('aryNewsCategory', $aryNewsCategory);
        $this->assign('ulId', $ulId);
        $this->assign('nextUlId', $nextUlId);
        $this->assign('parentCategoryId', $parentCategoryId);
        $aryPostParam = $this->getAllPostParams();
        $this->assign('perNewsCategoryAdd', $aryPostParam['perNewsCategoryAdd']);
        $this->assign('perNewsCategoryEdit', $aryPostParam['perNewsCategoryEdit']);
        $this->assign('perNewsCategoryDelete', $aryPostParam['perNewsCategoryDelete']);
        $this->assign('isMaster', $aryPostParam['isMaster']);
        if ($parentCategoryId != 0) {
            $this->_objAdminModule->getCategory($aryCategory);
            $strCatOption = $this->buildTreeCategoryOption($aryCategory);
            $this->assign('strCatOption', $strCatOption);
            $this->assign('parentCategoryId', $parentCategoryId);
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['listNewsCategory'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-news-left-category');
        $aryResult['contentNewsCategory'] = $this->getViewTemplate('admin/blackadmin', 'admin-list-news-content-category');
        $aryResult['ulId'] = $ulId;
        $aryResult['nextUlId'] = $nextUlId;
        $aryResult['catOption'] = $this->getViewTemplate('admin/blackadmin', 'admin-news-edit-content');
        $aryResult['news_product_category'] = $aryCategoryData[0]['news_category_product_category'];
        echo json_encode($aryResult);
    }

    public function updateNewsCategoryContent() {
        $aryParam = $this->getAllPostParams();
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'news_category_id',
                'math' => '=',
                'value' => $aryParam['news_category_id']
            )
        );
        $aryData = array();
        $aryData['news_category_name'] = $aryParam['edit_news_category_name'];
        $aryData['news_category_title'] = $aryParam['edit_news_category_title'];
        $aryData['news_category_keywords'] = $aryParam['edit_news_category_keywords'];
        $aryData['news_category_description'] = $aryParam['edit_news_category_description'];
        $intOk = $this->_objAdminModule->editNewsCatById($aryData, $aryConfig);
        if ($aryParam['product_category_id'] != 0 && $intOk == 1) {
            $this->editNewsProductCategory();
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        echo json_encode($aryResult);
    }

    public function showAddCategoryNews() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;
        $aryResult = array();
        $intOk = $this->_objAdminModule->getNewsCategory($aryCategory, 0);
        $this->assign('aryNewsCategory', $aryCategory);
        $this->_objAdminModule->getCategory($aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'editor-add-sub-news-category');
        echo json_encode($aryResult);
    }

    public function saveNewsCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;
        $aryParam = $this->getAllPostParams();
        $aryNewsCategoryName = $aryParam['news_category_name'];
        $aryShowStatus = $aryParam['news_category_is_show'];
        $aryProductCategoryId = $aryParam['news_product_category_id'];
        $parentNewsCat = $aryParam['news_cat_id_hidden'];
        $countItem = count($aryNewsCategoryName);
        $count = 0;
        $aryError = array();
        $aryResult = array();
        foreach ($aryNewsCategoryName as $key => $value) {
            if ($value == '') {
                $count++;
            }
        }

        if ($parentNewsCat == '') {
            $aryError[] = _NEWS_EMPTY_PARENT_CATEGORY_NAME;
        }

        if ($countItem == $count) {
            $aryError[] = _NEWS_EMPTY_CATEGORY_NAME;
        }

        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }
        if ($parentNewsCat == 0) {
            $level = 0;
        } else {
            $aryLevel = $this->_objAdminModule->getNewsCatParentPath($parentNewsCat);
            $level = count($aryLevel) + 1;
        }
        $newsTotalChild = 0;
        foreach ($aryNewsCategoryName as $key => $value) {
            if ($value != '') {
                $aryNewsCategory = array();
                $aryNewsCategory['news_category_name'] = $value;
                $aryNewsCategory['news_category_is_show'] = $aryShowStatus[$key];
                $aryNewsCategory['news_category_parent'] = $parentNewsCat;
                $aryNewsCategory['news_category_level'] = $level;
                $aryNewsCategory['news_category_filter'] = $this->filterUnicode($value);
                $aryNewsCategory['news_category_product_category'] = $aryProductCategoryId[$key];
                $aryProductChilCatId = $this->_objAdminModule->getCategoryChildPath($aryProductCategoryId[$key]);
                array_push($aryProductChilCatId, $aryProductCategoryId[$key]);
                $aryNewsCategory['news_category_product_child_cat'] = implode(",", $aryProductChilCatId);
                $newsTotalChild++;
                $intOk = $this->_objAdminModule->insertNewsCategory($aryNewsCategory, $lastCategoryId);
                if ($intOk == 1) {
                    $config = array(
                        array(
                            'keyword' => 'WHERE',
                            'field' => 'news_category_id',
                            'math' => '=',
                            'value' => $lastCategoryId
                        )
                    );
                    $aryCatEdit = array();
                    $aryCatEdit['news_category_order'] = $lastCategoryId;
                    $intOk = $this->_objAdminModule->editNewsCatById($aryCatEdit, $config);
                }
            }
        }

        if ($intOk == 1) {
            $intOk = $this->_objAdminModule->updateTotalChildNewsCat($parentNewsCat, $newsTotalChild);
        }
        $flagFile = 'tintuc_home_menu_flag';
        $this->setFlagCacheFile($flagFile);
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _NEWS_SAVE_CATEGORY_SUCCESS;
        echo json_encode($aryResult);
    }

    public function checkExistNewsCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $intOk = 1;
        $newsCategoryId = $this->getParam('newsCategoryId');
        $selectId = $this->getParam('selectId');
        $type = $this->getParam('type');
        $nextSelectId = $selectId + 1;
        if ($newsCategoryId == 0) {
            $intOk = -2;
        }
        $aryNewsCategory = array();
        if ($intOk == 1) {
            $intOk = $this->_objAdminModule->getNewsCategory($aryNewsCategory, $newsCategoryId);
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['selectId'] = $nextSelectId;
        $aryResult['aryCategory'] = $aryNewsCategory;
        echo json_encode($aryResult);
    }

    public function editNewsProductCategory() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $type = $this->getParam('type');
        $newsCategoryId = $aryParam['news_category_id'];
        $productCategoryId = $aryParam['product_category_id'];
        $aryResult = array();
        $aryError = array();
        if ($newsCategoryId == 0 || $newsCategoryId == '') {
            $aryError[] = _NEWS_EMPTY_CATEGORY_ID;
        }
        if ($productCategoryId == 0) {
            $aryError[] = _NEWS_EMPTY_PRODUCT_CATEGORY;
        }
        if (count($aryError) > 0) {
            $aryResult['intOk'] = -2;
            $aryResult['strError'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }
        $aryUpdate = array();
        $aryUpdate['news_category_product_category'] = $productCategoryId;
        $aryProductChilCatId = $this->_objAdminModule->getCategoryChildPath($productCategoryId);
        array_push($aryProductChilCatId, $productCategoryId);
        $aryUpdate['news_category_product_child_cat'] = implode(",", $aryProductChilCatId);
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'news_category_id',
                'math' => '=',
                'value' => $newsCategoryId
            )
        );

        $intOk = $this->_objAdminModule->updatePNewsProductCategory($aryUpdate, $aryConfig);
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _NEWS_EDIT_PRODUCT_CATEGORY_SUCCESS;
        if ($type == 'noForm') {
            echo json_encode($aryResult);
        }
    }

    //end news

    public function getTemplateManageGeneral() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $aryResult = array();

        $type = $this->getParam('type');

        $intOk = $this->_objAdminModule->getCommonData($aryCommonData);

        $aryResult['intOk'] = $intOk;
        $aryResult['type'] = $type;
        $aryResult['manageData'] = $aryCommonData[0];
        echo json_encode($aryResult);
    }

    public function saveCurrency() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $aryParam = $this->getAllPostParams();

        $aryCurrency['common_currency'] = $aryParam['common_currency'];

        $aryError = array();

        $aryResult = array();

        $objValidator = new Validator();

        $flag = $objValidator->validateEmpty($aryParam['common_currency']);

        if ($flag == true) {

            $aryError[] = _CURRENCY_IS_EMPTY;
        } else {

            $flag = $objValidator->validateNumber($aryParam['common_currency']);

            if ($flag == false) {

                $aryError[] = _CURRENCY_IS_NOT_NUMBER;
            }
        }

        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }

        $intOk = $this->_objAdminModule->updateCurrentcy($aryCurrency);

//        echo $intOk;
        //cap nhat tien do theo ty gia 20650 bang cach chi tien viet cho ty gia 20650
//        $k = 0;
//
//        if ($intOk == 1) {
//            $intOk = $this->_objAdminModule->getProductPrice($aryProductPrice);
//            foreach ($aryProductPrice as $key => $value) {
//                $aryUsdPrice[$k]['product_id'] = $value['product_id'];
//                $aryUsdPrice[$k]['product_price_usd'] = round(($value['product_price_vnd'] / $aryParam['common_currency']), 3);
//                $k++;
//            }
//        }
//        if (isset($aryUsdPrice[0]['product_id'])) {
//            foreach ($aryUsdPrice as $key => $value) {
//
//                $aryConfig = array(
//                    array(
//                        'keyword' => 'where',
//                        'field' => 'product_id',
//                        'value' => $value['product_id'],
//                        'math' => '='
//                    )
//                );
//
//                $aryPriceUpdate = array();
//                $aryPriceUpdate['product_price_usd'] = $value['product_price_usd'];
//
//                $intOk = $this->_objAdminModule->updateProductPrice($aryPriceUpdate, $aryConfig);
//
//            }
//        }
        $n = 0;
        if ($intOk == 1) {
            $this->_objAdminModule->getProductUsdPrice($aryProductUsdPrice);
            if (isset($aryProductUsdPrice[0])) {
                foreach ($aryProductUsdPrice as $key => $value) {
                    if (isset($value['product_price_usd'])) {
                        $aryProductVndPrice[$n]['product_id'] = $value['product_id'];
                        $aryProductVndPrice[$n]['product_price_vnd'] = ceil($aryParam['common_currency'] * $value['product_price_usd']);
                        $n++;
                    }
                }
            }
        }

        //cap nhat lai tien viet khi da co gia USD
        if (isset($aryProductVndPrice[0]['product_id'])) {

            foreach ($aryProductVndPrice as $key => $value) {

                $aryConfig = array(
                    array(
                        'keyword' => 'where',
                        'field' => 'product_id',
                        'value' => $value['product_id'],
                        'math' => '='
                    )
                );

                $aryPriceUpdate = array();
                $aryPriceUpdate['product_price_vnd'] = $value['product_price_vnd'];

                $intOk = $this->_objAdminModule->updateProductPrice($aryPriceUpdate, $aryConfig);
            }
        }

        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _CURRENCY_UPDATE_SUCCESS;

        echo json_encode($aryResult);
    }

    public function deleteNewsById() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $newsId = $this->getParam('newsId');

        $aryNewsDelete = array();

        $aryNewsDelete['news_del_flag'] = 1;

        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'news_id',
                'math' => '=',
                'value' => $newsId
            )
        );

        $intOk = $this->_objAdminModule->deleteNewsById($aryNewsDelete, $aryConfig);

        if ($intOk == 1) {

            $this->_objAdminModule->getNewsImagesById($newsId, $aryImages);

            $this->deleteImage($aryImages[0]['news_main_image'], 'main');

            $this->deleteImage($aryImages[0]['news_large_image'], 'large');
        }

        $this->setFlagOfSaveEditNews($newsId);

        $cacheFile = array();

        $cacheFile[] = 'tintuc_chi_tiet_' . $newsId;

        $cacheFile[] = 'tintuc_chi_tiet_' . $newsId . '_flag';

        foreach ($cacheFile as $key => $value) {
            $this->deleteCacheFile($value);
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _NEWS_DELETE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function changeCurrency() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $priceUsd = $this->getParam('priceUsd');
        $product_price_usd = $this->getParam('product_price_usd');
        $product_price_vnd = $this->getParam('product_price_vnd');
        $priceType = $this->getParam('priceType');
        switch ($priceType) {
            case "priceIn":
                $formatUsd = 'change_price_usd_in';
                $formatVnd = 'change_price_vnd_in';
                break;
            case "priceOut":
                $formatUsd = 'change_price_usd';
                $formatVnd = 'change_price_1';
                break;
        }
        if ($priceUsd != '') {
            if (is_numeric($priceUsd) == false) {
                $aryResult = array();
                $aryResult['intOk'] = -2;
                $aryResult['strError'] = _PRICE_IS_NOT_NUMBER;
                $aryResult['product_price_usd'] = $product_price_usd;
                $aryResult['product_price_vnd'] = $product_price_vnd;
                $aryResult['format_usd'] = $formatUsd;
                $aryResult['format_vnd'] = $formatVnd;
                echo json_encode($aryResult);
                return;
            }
        }

        $intOk = $this->_objAdminModule->getCurrency($aryData);
        $currency = $aryData[0]['common_currency'];
        $priceVnd = ceil($priceUsd * $currency);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['priceVnd'] = $priceVnd;
        $aryResult['product_price_usd'] = $product_price_usd;
        $aryResult['product_price_vnd'] = $product_price_vnd;
        $aryResult['format_usd'] = $formatUsd;
        $aryResult['format_vnd'] = $formatVnd;
        echo json_encode($aryResult);
    }

    public function changeVndToUsd() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $priceVnd = $this->getParam('priceVnd');
        $product_price_usd = $this->getParam('product_price_usd');
        $product_price_vnd = $this->getParam('product_price_vnd');
        $priceType = $this->getParam('priceType');
        switch ($priceType) {
            case "priceIn":
                $formatUsd = 'change_price_usd_in';
                $formatVnd = 'change_price_vnd_in';
                break;
            case "priceOut":
                $formatUsd = 'change_price_usd';
                $formatVnd = 'change_price_1';
                break;
        }
        if ($priceVnd != '') {
            if (is_numeric($priceVnd) == false) {
                $aryResult = array();
                $aryResult['intOk'] = -2;
                $aryResult['strError'] = _PRICE_IS_NOT_NUMBER;
                $aryResult['product_price_vnd'] = $product_price_vnd;
                $aryResult['product_price_usd'] = $product_price_usd;
                $aryResult['format_usd'] = $formatUsd;
                $aryResult['format_vnd'] = $formatVnd;
                echo json_encode($aryResult);
                return;
            }
        }

        $intOk = $this->_objAdminModule->getCurrency($aryData);
        $currency = $aryData[0]['common_currency'];
        $priceUsd = round($priceVnd / $currency, 2);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['priceUsd'] = $priceUsd;
        $aryResult['product_price_vnd'] = $product_price_vnd;
        $aryResult['product_price_usd'] = $product_price_usd;
        $aryResult['format_usd'] = $formatUsd;
        $aryResult['format_vnd'] = $formatVnd;
        echo json_encode($aryResult);
    }

    public function showCustomerProductLink() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $type = $this->getParam('type');

        switch ($type) {
            case "new":
                $status = 0;
                break;
            case "processing":
                $status = 1;
                break;
            case "processed":
                $status = 2;
                break;
        }
        $intOk = $this->_objAdminModule->getCustommerProductLink($status, $aryData);
        foreach ($aryData as $key => $value) {
            $aryProductId[$value['mct_customer_link_product_id']] = $value['mct_customer_link_product_id'];
            $aryCustomerId[$value['mct_customer_link_customer_id']] = $value['mct_customer_link_customer_id'];
        }
//        print_r($aryData);
        $aryCustomerNewId = array_keys($aryCustomerId);
        $strCustomerId = implode(",", $aryCustomerNewId);
        if ($strCustomerId != '') {
            $intOk = $this->_objAdminModule->getCustomerInfoByListId($strCustomerId, $aryCustomerInfo);
        }
//        print_r($aryCustomerInfo);
        foreach ($aryCustomerInfo as $key => $value) {
            $aryCustomerLink[$value['customer_id']]['customer_id'] = $value['customer_id'];
            $aryCustomerLink[$value['customer_id']]['customer_full_name'] = $value['customer_full_name'];
            $aryCustomerLink[$value['customer_id']]['customer_address'] = $value['customer_address'];
            $aryCustomerLink[$value['customer_id']]['customer_mobile_phone'] = $value['customer_mobile_phone'];
        }
//        print_r($aryCustomerLink);
        $productId = array_keys($aryProductId);
        $strProductId = implode(",", $productId);
        if ($strProductId != '') {
            $intOk = $this->_objAdminModule->getProductByListId($strProductId, $aryProduct);
        }

        foreach ($aryProduct as $key => $value) {
            $aryNewProduct[$value['product_id']]['product_id'] = $value['product_id'];
            $aryNewProduct[$value['product_id']]['product_title'] = $value['product_title'];
            $aryNewProduct[$value['product_id']]['product_title_filter'] = $value['product_title_filter'];
            $aryNewProduct[$value['product_id']]['product_main_image'] = $value['product_main_image'];
            $aryNewProduct[$value['product_id']]['product_price_vnd'] = $value['product_price_vnd'];
        }
//        print_r($aryNewProduct);
        $aryCustomer = array();
        foreach ($aryData as $key => $value) {
            $aryCustomer[$value['mct_customer_link_customer_id']]['customer_id'] = $aryCustomerLink[$value['mct_customer_link_customer_id']]['customer_id'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['customer_full_name'] = $aryCustomerLink[$value['mct_customer_link_customer_id']]['customer_full_name'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['customer_address'] = $aryCustomerLink[$value['mct_customer_link_customer_id']]['customer_address'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['customer_mobile_phone'] = $aryCustomerLink[$value['mct_customer_link_customer_id']]['customer_mobile_phone'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['product_id'] = $aryNewProduct[$value['mct_customer_link_product_id']]['product_id'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['product_title'] = $aryNewProduct[$value['mct_customer_link_product_id']]['product_title'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['product_price_vnd'] = $aryNewProduct[$value['mct_customer_link_product_id']]['product_price_vnd'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['product_main_image'] = $aryNewProduct[$value['mct_customer_link_product_id']]['product_main_image'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['mct_customer_status'] = $value['mct_customer_status'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['mct_customer_date_process'] = $value['mct_customer_date_process'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['link'][$value['mct_customer_link_id']]['mct_customer_link_link'] = $value['mct_customer_link_link'];
            $aryCustomer[$value['mct_customer_link_customer_id']]['product'][$value['mct_customer_link_product_id']]['link'][$value['mct_customer_link_id']]['mct_customer_link_send_date'] = $value['mct_customer_link_send_date'];
        }
//        print_r($aryCustomer);
        $this->assign('aryCustomer', $aryCustomer);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
//        $aryResult['content'] = $this->setViewTemplate('admin/blackadmin', 'mct-customer-link');
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'mct-customer-link');
        echo json_encode($aryResult);
    }

    public function viewDetailCustomerLink() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $customerId = $this->getParam('custommerId');
        $productId = $this->getParam('productId');
        $aryConditions = array();
        $aryConditions['mct_customer_link_customer_id'] = $customerId;
        $aryConditions['mct_customer_link_product_id'] = $productId;
        $intOk = $this->_objAdminModule->getProductLinkByCustomerId($aryConditions, $aryData);
        foreach ($aryData as $key => $value) {
            $productId = $value['mct_customer_link_product_id'];
            $customerId = $value['mct_customer_link_customer_id'];
        }
        $intOk = $this->_objAdminModule->getProductById($productId, $aryProductData);
        $this->assign('aryProduct', $aryProductData[0]);
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($customerId, $aryCustomerInfo);
        $this->assign('aryCustomerInfo', $aryCustomerInfo[0]);
        $this->assign('aryProductLink', $aryData);
        $this->assign('customerId', $customerId);
        $this->assign('productId', $productId);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'customer_view_detail_product_link');
        echo json_encode($aryResult);
    }

    public function updateStatusCustomerLink() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $statusId = $this->getParam('statusId');
        $aryParam = $this->getAllPostParams();
        $customerId = $aryParam['customer_link_customer_id'];
        $productId = $aryParam['customer_link_product_id'];
        $intOk = $this->_objAdminModule->updateStatusCustomerLinkData($statusId, $customerId, $productId);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _CUSTOMER_LINK_UPDATE_STATUS_SUCCESS;
        echo json_encode($aryResult);
    }

    public function deleteMember() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $memberId = $this->getParam('memberId');
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'member_id',
                'math' => '=',
                'value' => $memberId
            )
        );
        $aryUpdateMember = array();
        $aryUpdateMember['member_del_flag'] = 1;
        $intOk = $this->_objAdminModule->deleteMemberById($aryConfig, $aryUpdateMember);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _MEMBER_DELETE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function getListCustomer() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $page = $this->getParam('page');
        $aryConditions = array();
        $aryConditions['record_per_page'] = 5;
        $aryConditions['current_page'] = $page;
        $intOk = $this->_objAdminModule->getListCustomerInfo($aryConditions, $aryCustomerInfo);
//       print_r($aryCustomerInfo);
        $strPaging = $this->AjaxPagination($aryCustomerInfo['paging']);
        $this->assign('strPaging', $strPaging);
        //$this->assign('page', $page);
        $this->assign('aryCustomerInfo', $aryCustomerInfo);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['list_customer'] = $this->getViewTemplate('admin/blackadmin', 'customer_list_customer');
        echo json_encode($aryResult);
    }

    public function getCustomerCTV() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryConditions = array();
        $page = $this->getParam('page');
        $aryConditions['current_page'] = $page;
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $intOk = $this->_objAdminModule->getListCustomerByKdId($aryConditions, $aryCustomerCTV);
//        print_r($aryCustomerCTV);
        $this->assign('aryCustomerCTV', $aryCustomerCTV['data']);
        $this->setActionJSPaging("AdminController.getListCustomerCTV(");
        $strPaging = $this->AjaxPagination($aryCustomerCTV['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['list_customer'] = $this->getViewTemplate('admin/blackadmin', 'customer_list_CTV');
        echo json_encode($aryResult);
    }

    public function getMyCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryLogin = $this->getSession('login');
        $memberId = $aryLogin['member_id'];
        $this->_objAdminModule->getListCustomerCTV($aryConditions, $aryCustomerCtv, $memberId);
        $this->_objAdminModule->getTotalCtvProductAndProfit($aryTotalProfit);
        foreach ($aryTotalProfit as $key => $value) {
            $aryCtvTotalProfit[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
            $aryCtvTotalProfit[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
            $aryCtvTotalProfit[$value['customer_product_customer_id']]['customer_product_ctv_profit']+=$value['customer_product_ctv_profit'];
            $aryCtvTotalProfit[$value['customer_product_customer_id']]['customer_product_kd_profit']+=$value['customer_product_kd_profit'];
            if ($value['customer_product_status_finish'] == 1) {
                $aryTotalProductFinish[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryTotalProductFinish[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryTotalProductFinish[$value['customer_product_customer_id']]['customer_product_ctv_profit']+=$value['customer_product_ctv_profit'];
                $aryTotalProductFinish[$value['customer_product_customer_id']]['customer_product_kd_profit']+=$value['customer_product_kd_profit'];
            } else {
                $aryTotalCurrentProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryTotalCurrentProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryTotalCurrentProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+=$value['customer_product_ctv_profit'];
                $aryTotalCurrentProduct[$value['customer_product_customer_id']]['customer_product_kd_profit']+=$value['customer_product_kd_profit'];
            }
        }
        $aryConditions = array();
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $page = $this->getParam('page');
        $aryConditions['current_page'] = $page;
        $aryConditions['customer_of_member_id'] = $memberId;

        $intOk = $this->_objAdminModule->getListCustomerByKdId($aryConditions, $aryCustomer);

        $month = date("m");
        $year = date("Y");
        $this->assign('month', $month);
        $this->assign('year', $year);
        $aryConditions['customer_product_month_process'] = intval($month);
        $aryConditions['customer_product_year_process'] = $year;
        $aryConditions['customer_product_kd_id'] = $memberId;

        $this->_objAdminModule->getCustomerProductByMonth($aryConditions, $aryProductCurrentMonth);

        foreach ($aryProductCurrentMonth as $key => $value) {
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_kd_profit']+=$value['customer_product_kd_profit'];
            if ($value['customer_product_status_finish'] == 1) {
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_kd_profit']+=$value['customer_product_kd_profit'];
            } else {
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_kd_profit']+=$value['customer_product_kd_profit'];
            }
        }

//        print_r($aryTotalCustomerProduct);

        $this->assign('aryCustomerCtv', $aryCustomerCtv);

        $this->assign('aryLogin', $aryLogin);
        $this->assign('aryTotalProductFinish', $aryTotalProductFinish);
        $this->assign('aryTotalProduct', $aryTotalProduct);
        $this->assign('aryCurrentProduct', $aryCurrentProduct);
        $this->assign('aryTotalCustomerProduct', $aryTotalCustomerProduct);
        $this->assign('aryTotalCurrentProduct', $aryTotalCurrentProduct);
        $this->assign('memberId', $memberId);
        $this->assign('aryMemberKd', $aryMemberKd);
        $this->assign('aryCtv', $aryCustomer['data']);
        $this->assign('aryCtvTotalProfit', $aryCtvTotalProfit);
        $this->setActionJSPaging("AdminController.getMyCtv(");
        $strPaging = $this->AjaxPagination($aryCustomer['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['list_my_ctv'] = $this->getViewTemplate('admin/blackadmin', 'ctv_list_my_ctv');
        echo json_encode($aryResult);
    }

    public function viewDetailMyCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $custommerId = $this->getParam('custommerId');
        $aryConditions = array();
        $aryConditions['customer_product_customer_id'] = $custommerId;
        $aryConditions['customer_product_month_process'] = intval(date("m"));
        $aryConditions['customer_product_year_process'] = intval(date("Y"));
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($custommerId, $aryCustomerInfo);
        $this->_objAdminModule->getCustomerProductByCusId($aryConditions, $aryCustomerProduct);
        $this->assign('aryCustomerProduct', $aryCustomerProduct);
//        print_r($aryCustomerProduct);
        $this->assign('aryCustomer', $aryCustomerInfo[0]);
        $month = date("m-Y");
        $this->assign('month', $month);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'customer_view_customer');
        echo json_encode($aryResult);
    }

    public function viewDetailSearchDoanhSo() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $custommerId = $this->getParam('custommerId');
        $aryConditions = array();
        $aryConditions['customer_product_customer_id'] = $custommerId;
        $aryConditions['customer_product_month_process'] = intval(date("m"));
        $aryConditions['customer_product_year_process'] = intval(date("Y"));
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($custommerId, $aryCustomerInfo);
        $this->_objAdminModule->getCustomerProductByCusId($aryConditions, $aryCustomerProduct);
        $this->assign('aryCustomerProduct', $aryCustomerProduct);
        $this->assign('aryCustomer', $aryCustomerInfo[0]);
        $month = date("m-Y");
        $this->assign('month', $month);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'ctv_view_search_doanhso');
        echo json_encode($aryResult);
    }

    public function viewDetailDoanhsoCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $custommerId = $this->getParam('custommerId');
        $aryParam = $this->getAllPostParams();
        $aryConditions = array();
        $aryConditions['customer_product_customer_id'] = $custommerId;
        $aryConditions['customer_product_month_process'] = intval($aryParam['customer_product_month_process']);
        $aryConditions['customer_product_year_process'] = $aryParam['customer_product_year_process'];
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($custommerId, $aryCustomerInfo);
        $this->_objAdminModule->getCustomerProductByCusId($aryConditions, $aryCustomerProduct);
        $this->assign('aryCustomerProduct', $aryCustomerProduct);
        $this->assign('aryCustomer', $aryCustomerInfo[0]);
        $month = intval($aryParam['customer_product_month_process']);
        $year = $aryParam['customer_product_year_process'];
        $this->assign('month', $month);
        $this->assign('year', $year);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'ctv_view_detail_doanhso');
        echo json_encode($aryResult);
    }

    public function viewDetailSearchMyCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $custommerId = $this->getParam('custommerId');
        $aryParam = $this->getAllPostParams();
        $aryConditions = array();
        $aryConditions['customer_product_customer_id'] = $custommerId;
        $aryConditions['customer_product_month_process'] = intval($aryParam['customer_product_month_process']);
        $aryConditions['customer_product_year_process'] = $aryParam['customer_product_year_process'];
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($custommerId, $aryCustomerInfo);
        $this->_objAdminModule->getCustomerProductByCusId($aryConditions, $aryCustomerProduct);
        $this->assign('aryCustomerProduct', $aryCustomerProduct);
        $this->assign('aryCustomer', $aryCustomerInfo[0]);
        $month = intval($aryParam['customer_product_month_process']);
        $year = $aryParam['customer_product_year_process'];
        $this->assign('month', $month);
        $this->assign('year', $year);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'ctv_view_detail_my_ctv_doanhso');
        echo json_encode($aryResult);
    }

    public function addProductForCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
//        print_r($aryParam);
        $customerId = $aryParam['customer_product_customer_id'];
        $aryError = $this->validateCtvAddProduct($aryParam);
        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult = array();
            $aryResult['intOk'] = $intOk;
            $aryResult['aryError'] = $aryError;
            echo json_encode($aryResult);
            return;
        }
        $aryProductData = array();
        $aryProductData['customer_product_product_name'] = $aryParam['customer_product_product_name'];
        $aryProductData['customer_product_in_price'] = $aryParam['customer_product_in_price'];
        $aryProductData['customer_product_out_price'] = $aryParam['customer_product_out_price'];
        $aryProductData['customer_product_customer_id'] = $customerId;
        $aryProductData['customer_product_date_process'] = date("Y-m-d H:i:s");
        $aryLogin = $this->getSession('login');
        $memberId = $aryLogin['member_id'];
        $aryProductData['customer_product_kd_id'] = $memberId;
        $aryProductData['customer_product_month_process'] = date("m");
        $aryProductData['customer_product_year_process'] = date("Y");
        $aryProductData['customer_product_number'] = $aryParam['customer_product_number'];
        $aryProductData['customer_product_unit'] = $aryParam['customer_product_unit'];
        $aryProductData['customer_product_transport'] = $aryParam['customer_product_transport'];
        $aryProductData['customer_product_services'] = $aryParam['customer_product_services'];
        $aryProductData['customer_product_disparity'] = $aryParam['customer_product_disparity'];
        $aryProductData['customer_product_total_price'] = ($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']);
        $totalProfit = (($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * $aryParam['customer_product_number']);
        $aryProductData['customer_product_is_tax'] = $totalProfit * 0.25;
        $totalProfit = $totalProfit * 0.75;
        if (isset($aryParam['customer_product_transport']) && is_numeric($aryParam['customer_product_transport'])) {
            $totalProfit = $totalProfit - $aryParam['customer_product_transport'];
        }
        if (isset($aryParam['customer_product_services']) && is_numeric($aryParam['customer_product_services'])) {
            $totalProfit = $totalProfit - $aryParam['customer_product_services'];
        }
        $aryProductData['customer_product_total_profit'] = $totalProfit;
        $aryProductData['customer_product_ctv_profit'] = $totalProfit * 0.5;
        $aryProductData['customer_product_kd_profit'] = ($aryProductData['customer_product_ctv_profit'] * 0.2);
        $intOk = $this->_objAdminModule->insertProductCustomer($aryProductData);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _CUSTOMER_PRODUCT_SAVE_SUCCESS;
        $aryResult['customerId'] = $customerId;
        echo json_encode($aryResult);
    }

    public function saveEditProductForCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $type = $this->getParam('type');
        $aryError = $this->validateCtvAddProduct($aryParam);
        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult = array();
            $aryResult['intOk'] = $intOk;
            $aryResult['aryError'] = $aryError;
            echo json_encode($aryResult);
            return;
        }

        $aryProductData = array();
        $aryProductData['customer_product_product_name'] = $aryParam['customer_product_product_name'];
        $aryProductData['customer_product_in_price'] = $aryParam['customer_product_in_price'];
        $aryProductData['customer_product_out_price'] = $aryParam['customer_product_out_price'];

        $aryProductData['customer_product_date_finish'] = date("Y-m-d H:i:s");
        $aryProductData['customer_product_date_is_finish'] = date("d");
        $aryProductData['customer_product_month_finish'] = date("m");
        $aryProductData['customer_product_year_finish'] = date("Y");
        $aryProductData['customer_product_number'] = $aryParam['customer_product_number'];
        $aryProductData['customer_product_unit'] = $aryParam['customer_product_unit'];
        $aryProductData['customer_product_transport'] = $aryParam['customer_product_transport'];
        $aryProductData['customer_product_services'] = $aryParam['customer_product_services'];
        $aryProductData['customer_product_disparity'] = $aryParam['customer_product_disparity'];
        $aryProductData['customer_product_total_price'] = ($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']);
        $totalProfit = (($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * $aryParam['customer_product_number']);
        $aryProductData['customer_product_is_tax'] = $totalProfit * 0.25;
        $totalProfit = $totalProfit * 0.75;
        if (isset($aryParam['customer_product_transport']) && is_numeric($aryParam['customer_product_transport'])) {
            $totalProfit = $totalProfit - $aryParam['customer_product_transport'];
        }
        if (isset($aryParam['customer_product_services']) && is_numeric($aryParam['customer_product_services'])) {
            $totalProfit = $totalProfit - $aryParam['customer_product_services'];
        }
        $aryProductData['customer_product_total_profit'] = $totalProfit;
        $aryProductData['customer_product_ctv_profit'] = $totalProfit * 0.5;
        $aryProductData['customer_product_kd_profit'] = ($aryProductData['customer_product_ctv_profit'] * 0.2);
        $aryProductData['customer_product_status_finish'] = 0;
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'customer_product_id',
                'math' => '=',
                'value' => $aryParam['customer_product_id']
            )
        );
        $intOk = $this->_objAdminModule->updateCtvProduct($aryConfig, $aryProductData);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['type'] = $type;
        $aryResult['message'] = _CUSTOMER_PRODUCT_EDIT_CUSSECC;
        $aryResult['customer_id'] = $aryParam['customer_product_customer_id'];
        echo json_encode($aryResult);
    }

    public function validateCtvAddProduct($aryParam) {

        $objValidate = new Validator();
        $aryError = array();
        $flag = $objValidate->validateEmpty($aryParam['customer_product_product_name']);
        if ($flag == true) {
            $aryError['customer_product_product_name_error'] = _CUSTOMER_PRODUCT_NAME_EMPTY;
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_in_price']);
        if ($flag == true) {
            $aryError['customer_product_in_price_error'] = _CUSTOMER_PRODUCT_EMPTY_IN_PRICE;
        } else {
            $flag = $objValidate->validateNumber($aryParam['customer_product_in_price']);
            if ($flag == false) {
                $aryError['customer_product_in_price_error'] = _CUSTOMER_PRODUCT_ERROR_IN_PRICE;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_out_price']);
        if ($flag == true) {
            $aryError['customer_product_out_price_error'] = _CUSTOMER_PRODUCT_EMPTY_OUT_PRICE;
        } else {
            $flag = $objValidate->validateNumber($aryParam['customer_product_out_price']);
            if ($flag == false) {
                $aryError['customer_product_out_price_error'] = _CUSTOMER_PRODUCT_ERROR_OUT_PRICE;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_number']);
        if ($flag == true) {
            $aryError['customer_product_number_error'] = _CUSTOMER_PRODUCT_EMPTY_NUMBER;
        } else {
            $flag = $objValidate->validateNumber($aryParam['customer_product_number']);
            if ($flag == false) {
                $aryError['customer_product_number_error'] = _CUSTOMER_PRODUCT_ERROR_NUMBER;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_unit']);
        if ($flag == true) {
            $aryError['customer_product_unit_error'] = _CUSTOMER_PRODUCT_EMPTY_UNIT;
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_transport']);
        if ($flag == false) {
            $flag = $objValidate->validateNumber($aryParam['customer_product_transport']);
            if ($flag == false) {
                $aryError['customer_product_transport_error'] = _CUSTOMER_PRODUCT_ERROR_TRANSPORT;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_services']);
        if ($flag == false) {
            $flag = $objValidate->validateNumber($aryParam['customer_product_services']);
            if ($flag == false) {
                $aryError['customer_product_services_error'] = _CUSTOMER_PRODUCT_ERROR_SERVICES;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_disparity']);
        if ($flag == false) {
            $flag = $objValidate->validateNumber($aryParam['customer_product_disparity']);
            if ($flag == false) {
                $aryError['customer_product_disparity_error'] = _CUSTOMER_PRODUCT_ERROR_DISPARITY;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_number']);
        if ($flag == true) {
            $aryError['customer_product_number_error'] = _CUSTOMER_PRODUCT_EMPTY_NUMBER;
        }
        if ($aryParam['customer_product_in_price'] > $aryParam['customer_product_out_price']) {
            $aryError['customer_product_in_price_error'] = _CUSTOMER_PRODUCT_IN_LARGE_THAN_OUT;
        }
        return $aryError;
    }

    public function validateAddMyProduct($aryParam) {
        $objValidate = new Validator();
        $aryError = array();
        $flag = $objValidate->validateEmpty($aryParam['customer_full_name']);
        if ($flag == true) {
            $aryError['customer_full_name_error_2'] = _CUSTOMER_EMPTY_FULL_NAME;
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_email']);
        if ($flag == true) {
//            $aryError['customer_email_error'] = _CUSTOMER_EMPTY_EMAIL;
        } else {
            $flag = $objValidate->validateMail($aryParam['customer_email']);
            if ($flag == false) {
                $aryError['customer_email_error_2'] = _CUSTOMER_ERROR_EMAIL;
            } else {
                $checkEmail = $aryParam['customer_email'];
                $intOk = $this->_objAdminModule->getCustomerEmail($checkEmail, $aryCustumerEmail);
                if (count($aryCustumerEmail) > 0) {
                    $aryError['customer_email_error_2'] = _CUSTOMER_EMAIL_ERROR;
                }
            }
        }

        $flag = $objValidate->validateEmpty($aryParam['customer_zone_id']);
        if ($flag == true) {
            $aryError['customer_zone_id_error_2'] = _CUSTOMER_EMPTY_PROVINCE;
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_mobile_phone']);
        if ($flag == false) {
            $flag = $objValidate->validatePhone($aryParam['customer_mobile_phone']);
            if ($flag == false) {
                $aryError['customer_mobile_phone_error_2'] = _CUSTOMER_ERROR_FORMAT_PHONE;
            }
        } else {
            $aryError['customer_mobile_phone_error_2'] = _CUSTOMER_EMPTY_MOBILE_PHONE;
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_home_phone']);
        if ($flag == false) {
            $flag = $objValidate->validatePhone($aryParam['customer_home_phone']);
            if ($flag == false) {
                $aryError['customer_home_phone_error_2'] = _CUSTOMER_ERROR_FORMAT_PHONE;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_address']);
        if ($flag == true) {
            $aryError['customer_address_error_2'] = _CUSTOMER_EMPTY_ADRESS;
        }
        //validate birthday
//        $flag = $objValidate->validateEmpty($aryParam['day']);
//        if ($flag == true) {
//            $aryError['customer_birthday_error_2'] = _CUSTOMER_EMPTY_DAY;
//        }
//        $flag = $objValidate->validateEmpty($aryParam['month']);
//        if ($flag == true) {
//            $aryError['customer_birthday_error_2'] = _CUSTOMER_EMPTY_MONTH;
//        }
//        $flag = $objValidate->validateEmpty($aryParam['year']);
//        if ($flag == true) {
//            $aryError['customer_birthday_error_2'] = _CUSTOMER_EMPTY_YEAR;
//        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_product_name']);
        if ($flag == true) {
            $aryError['customer_product_product_name_error'] = _CUSTOMER_PRODUCT_NAME_EMPTY;
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_in_price']);
        if ($flag == true) {
            $aryError['customer_product_in_price_error'] = _CUSTOMER_PRODUCT_EMPTY_IN_PRICE;
        } else {
            $flag = $objValidate->validateNumber($aryParam['customer_product_in_price']);
            if ($flag == false) {
                $aryError['customer_product_in_price_error'] = _CUSTOMER_PRODUCT_ERROR_IN_PRICE;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_out_price']);
        if ($flag == true) {
            $aryError['customer_product_out_price_error'] = _CUSTOMER_PRODUCT_EMPTY_OUT_PRICE;
        } else {
            $flag = $objValidate->validateNumber($aryParam['customer_product_out_price']);
            if ($flag == false) {
                $aryError['customer_product_out_price_error'] = _CUSTOMER_PRODUCT_ERROR_OUT_PRICE;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_number']);
        if ($flag == true) {
            $aryError['customer_product_number_error'] = _CUSTOMER_PRODUCT_EMPTY_NUMBER;
        } else {
            $flag = $objValidate->validateNumber($aryParam['customer_product_number']);
            if ($flag == false) {
                $aryError['customer_product_number_error'] = _CUSTOMER_PRODUCT_ERROR_NUMBER;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_unit']);
        if ($flag == true) {
            $aryError['customer_product_unit_error'] = _CUSTOMER_PRODUCT_EMPTY_UNIT;
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_transport']);
        if ($flag == false) {
            $flag = $objValidate->validateNumber($aryParam['customer_product_transport']);
            if ($flag == false) {
                $aryError['customer_product_transport_error'] = _CUSTOMER_PRODUCT_ERROR_TRANSPORT;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_services']);
        if ($flag == false) {
            $flag = $objValidate->validateNumber($aryParam['customer_product_services']);
            if ($flag == false) {
                $aryError['customer_product_services_error'] = _CUSTOMER_PRODUCT_ERROR_SERVICES;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_disparity']);
        if ($flag == false) {
            $flag = $objValidate->validateNumber($aryParam['customer_product_disparity']);
            if ($flag == false) {
                $aryError['customer_product_disparity_error'] = _CUSTOMER_PRODUCT_ERROR_DISPARITY;
            }
        }
        $flag = $objValidate->validateEmpty($aryParam['customer_product_number']);
        if ($flag == true) {
            $aryError['customer_product_number_error'] = _CUSTOMER_PRODUCT_EMPTY_NUMBER;
        }
        if ($aryParam['customer_product_in_price'] > $aryParam['customer_product_out_price']) {
            $aryError['customer_product_in_price_error'] = _CUSTOMER_PRODUCT_IN_LARGE_THAN_OUT;
        }


        return $aryError;
    }

    public function statisticsProfit() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $memberId = $this->getParam('memberId');
        if ($memberId != 0 && is_numeric($memberId)) {
            $kdId = $memberId;
        }


        $this->_objAdminModule->getListCustomerCTV($aryConditions, $aryCustomerCtv);

        $this->_objAdminModule->getListCtvByProduct($aryCtvProduct, $aryKd, $kdId);

        $this->_objAdminModule->getTotalCtvProductAndProfit($aryTotalProfit);

        foreach ($aryTotalProfit as $key => $value) {
            $aryCtvTotalProfit[$value['customer_statistics_cus_id']]['customer_statistics_cus_id'] = $value['customer_statistics_cus_id'];
            $aryCtvTotalProfit[$value['customer_statistics_cus_id']]['customer_statistics_total_product']+=$value['customer_statistics_total_product'];
            $aryCtvTotalProfit[$value['customer_statistics_cus_id']]['customer_statistics_total_profit']+=$value['customer_statistics_total_profit'];
        }

        foreach ($aryKd as $key => $value) {
            $aryMemberKdId[$value['customer_product_kd_id']] = $value['customer_product_kd_id'];
        }
        $aryMemberKdId = array_keys($aryMemberKdId);
        $strMemberKdId = implode(",", $aryMemberKdId);
        if ($strMemberKdId != '') {
            $this->_objAdminModule->getMemberKdByListId($strMemberKdId, $aryMemberKd);
        }
        foreach ($aryCtvProduct as $key => $value) {
            $aryCustomerId[$value['customer_product_customer_id']] = $value['customer_product_customer_id'];
        }
        $aryCustomerId = array_keys($aryCustomerId);
        $listCustomerId = implode(",", $aryCustomerId);
        $aryConditions = array();
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $page = $this->getParam('page');
        $aryConditions['current_page'] = $page;
        if ($listCustomerId != '') {
            $intOk = $this->_objAdminModule->getListCustomerByListId($aryConditions, $aryCustomer, $listCustomerId);
        }
        $month = date("m");
        $year = date("Y");
        $this->assign('month', $month);
        $this->assign('year', $year);
        $aryConditions['customer_product_month_process'] = intval($month);
        $aryConditions['customer_product_year_process'] = $year;
        $aryConditions['customer_product_kd_id'] = $memberId;

        $this->_objAdminModule->getCustomerProductByMonth($aryConditions, $aryProductCurrentMonth);

        foreach ($aryProductCurrentMonth as $key => $value) {
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            if ($value['customer_product_status_finish'] == 1) {
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            } else {
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            }
        }

        $this->assign('aryTotalProduct', $aryTotalProduct);
        $this->assign('aryCurrentProduct', $aryCurrentProduct);
        $this->assign('aryTotalCustomerProduct', $aryTotalCustomerProduct);
        $this->assign('aryCustomerCtv', $aryCustomerCtv);
        $this->assign('memberId', $memberId);
        $this->assign('aryMemberKd', $aryMemberKd);
        $this->assign('aryCtv', $aryCustomer['data']);
        $this->assign('aryCtvTotalProfit', $aryCtvTotalProfit);
        $this->setActionJSPaging("AdminController.statisticsProfit('$memberId',");
        $strPaging = $this->AjaxPagination($aryCustomer['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['list_my_ctv'] = $this->getViewTemplate('admin/blackadmin', 'ctv_thongke_doanhso');
        $aryResult['list_kd'] = $this->getViewTemplate('admin/blackadmin', 'ctv_thongke_list_kd');
        echo json_encode($aryResult);
    }

    public function searchCtvProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $objValidator = new Validator();
        $aryError = array();
        $flag = $objValidator->validateEmpty($aryParam['customer_product_month_process']);
        if ($flag == true) {
            $aryError[] = _SEARCH_CTV_EMPTY_MONTH;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_product_year_process']);
        if ($flag == true) {
            $aryError[] = _SEARCH_CTV_EMPTY_YEAR;
        }
        if (count($aryError) > 0) {
            $aryResult = array();
            $aryResult['intOk'] = -2;
            $aryResult['message'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }
        $kdMemberId = $this->getParam('memberId');
        if ($kdMemberId == 0) {
            $memberId = $aryParam['customer_product_kd_id'];
        } else {
            $memberId = $kdMemberId;
        }
        if ($memberId != 0 && is_numeric($memberId)) {
            $kdId = $memberId;
        }
        if ($aryParam['customer_product_customer_id'] != 0) {
            $ctvId = $aryParam['customer_product_customer_id'];
        }
        $intOk = $this->_objAdminModule->getListCtvByProduct($aryCtvProduct, $aryKd, $kdId, $ctvId);
//        print_r($aryCtvProduct);
        foreach ($aryKd as $key => $value) {
            $aryMemberKdId[$value['customer_product_kd_id']] = $value['customer_product_kd_id'];
        }
        $aryMemberKdId = array_keys($aryMemberKdId);
        $strMemberKdId = implode(",", $aryMemberKdId);
        if ($strMemberKdId != '') {
            $this->_objAdminModule->getMemberKdByListId($strMemberKdId, $aryMemberKd);
        }
        foreach ($aryCtvProduct as $key => $value) {
            $aryCustomerId[$value['customer_product_customer_id']] = $value['customer_product_customer_id'];
        }
        $aryCustomerId = array_keys($aryCustomerId);

        $listCustomerId = implode(",", $aryCustomerId);

        $aryConditions = array();
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $page = $this->getParam('page');
        $aryConditions['current_page'] = $page;
        if ($listCustomerId != '') {
            $intOk = $this->_objAdminModule->getListCustomerByListId($aryConditions, $aryCustomer, $listCustomerId);
        }
        $month = $aryParam['customer_product_month_process'];
        $year = $aryParam['customer_product_year_process'];
        $this->assign('month', $month);
        $this->assign('year', $year);
        $aryConditions['customer_product_month_process'] = intval($aryParam['customer_product_month_process']);
        $aryConditions['customer_product_year_process'] = $aryParam['customer_product_year_process'];
        $aryConditions['customer_product_kd_id'] = $memberId;
        if ($aryParam['customer_product_customer_id'] != 0) {
            $aryConditions['customer_product_customer_id'] = $aryParam['customer_product_customer_id'];
        }
        $this->_objAdminModule->getCustomerProductByMonth($aryConditions, $aryProductCurrentMonth);

        foreach ($aryProductCurrentMonth as $key => $value) {
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            if ($value['customer_product_status_finish'] == 1) {
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            } else {
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            }
        }
        $this->assign('aryTotalProduct', $aryTotalProduct);
        $this->assign('aryCurrentProduct', $aryCurrentProduct);
        $this->assign('aryTotalCustomerProduct', $aryTotalCustomerProduct);
        $this->assign('memberId', $memberId);

        $this->assign('aryMemberKd', $aryMemberKd);
        $this->assign('aryCtv', $aryCustomer['data']);
        $this->setActionJSPaging("AdminController.searchCtvProduct('$memberId',");
        $strPaging = $this->AjaxPagination($aryCustomer['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['list_statistics_ctv'] = $this->getViewTemplate('admin/blackadmin', 'ctv_search_doanhso');
        $aryResult['list_kd'] = $this->getViewTemplate('admin/blackadmin', 'ctv_search_list_kd');
        $aryResult['memberId'] = $memberId;
        echo json_encode($aryResult);
    }

    public function searchMyCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $aryLogin = $this->getSession('login');
        $memberId = $aryLogin['member_id'];
        $objValidator = new Validator();
        $aryError = array();
        $flag = $objValidator->validateEmpty($aryParam['customer_product_month_process']);
        if ($flag == true) {
            $aryError['empty_month'] = _SEARCH_CTV_EMPTY_MONTH;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_product_year_process']);
        if ($flag == true) {
            $aryError['empty_year'] = _SEARCH_CTV_EMPTY_YEAR;
        }
        if (count($aryError) > 0) {
            $aryResult = array();
            $aryResult['intOk'] = -2;
            $aryResult['message'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }
        $aryConditions = array();
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $page = $this->getParam('page');
        $aryConditions['current_page'] = $page;
        $aryConditions['customer_of_member_id'] = $memberId;
        if ($aryParam['customer_product_customer_id'] != 0) {
            $aryConditions['customer_id'] = $aryParam['customer_product_customer_id'];
        }

        $intOk = $this->_objAdminModule->getListCustomerByKdId($aryConditions, $aryCustomer);

        $month = $aryParam['customer_product_month_process'];
        $year = $aryParam['customer_product_year_process'];
        $this->assign('month', $month);
        $this->assign('year', $year);
        $aryConditions['customer_product_month_process'] = intval($month);
        $aryConditions['customer_product_year_process'] = $year;
        $aryConditions['customer_product_kd_id'] = $memberId;

        $this->_objAdminModule->getCustomerProductByMonth($aryConditions, $aryProductCurrentMonth);

        foreach ($aryProductCurrentMonth as $key => $value) {
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
            $aryTotalCustomerProduct[$value['customer_product_customer_id']]['customer_product_kd_profit']+= $value['customer_product_kd_profit'];
            if ($value['customer_product_status_finish'] == 1) {
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
                $aryTotalProduct[$value['customer_product_customer_id']]['customer_product_kd_profit']+= $value['customer_product_kd_profit'];
            } else {
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_customer_id'] = $value['customer_product_customer_id'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_total_product']+=$value['customer_product_number'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_ctv_profit']+= $value['customer_product_ctv_profit'];
                $aryCurrentProduct[$value['customer_product_customer_id']]['customer_product_kd_profit']+= $value['customer_product_kd_profit'];
            }
        }

        $this->assign('aryLogin', $aryLogin);

        $this->assign('aryTotalProduct', $aryTotalProduct);
        $this->assign('aryCurrentProduct', $aryCurrentProduct);
        $this->assign('aryTotalCustomerProduct', $aryTotalCustomerProduct);

        $this->assign('memberId', $memberId);
        $this->assign('aryMemberKd', $aryMemberKd);
        $this->assign('aryCtv', $aryCustomer['data']);
        $this->assign('aryCtvTotalProfit', $aryCtvTotalProfit);
        $this->setActionJSPaging("AdminController.searchMyCtv(");
        $strPaging = $this->AjaxPagination($aryCustomer['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['list_my_ctv'] = $this->getViewTemplate('admin/blackadmin', 'ctv_search_my_ctv');
        echo json_encode($aryResult);
    }

    public function finishProductStatucs() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        if (count($aryParam['update_finish_status']) == 0) {
            $intOk = -2;
            $aryResult = array();
            $aryResult['intOk'] = $intOk;
            $aryResult['message'] = 'Bạn chưa chọn sản phẩm nào trong danh sách.';
            echo json_encode($aryResult);
            return;
        }
        foreach ($aryParam['update_finish_status'] as $key => $value) {
            $aryCondition = array();
            $aryCondition['customer_product_status_finish'] = 1;
            $aryCondition['customer_product_date_finish'] = date("Y-m-d H:i:s");
            $aryCondition['customer_product_date_is_finish'] = date("d");
            $aryCondition['customer_product_month_finish'] = date("m");
            $aryCondition['customer_product_year_finish'] = date("Y");
            $aryConfig = array(
                array(
                    'keyword' => 'where',
                    'field' => 'customer_product_id',
                    'math' => '=',
                    'value' => $value
                )
            );

            $intOk = $this->_objAdminModule->updateFinishStatus($aryCondition, $aryConfig);
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = 'Bạn đã cập nhât thành công';
        $aryResult['customer_id'] = $aryParam['customer_id'];
        echo json_encode($aryResult);
    }

    public function editCtvProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $ctvProductId = $this->getParam('ctvProductId');
        $intOk = $this->_objAdminModule->getCtvproductById($ctvProductId, $aryCtvProduct);
        $aryRetult = array();
        $aryRetult['intOk'] = $intOk;
        $aryRetult['data'] = $aryCtvProduct[0];
        echo json_encode($aryRetult);
    }

    public function saveMyCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $intOk = 0;
        $aryParam = $this->getAllPostParams();
        $aryLogin = $this->getSession('login');
        $aryCustomer['customer_gender'] = $aryParam['customer_gender'];
        $aryCustomer['customer_full_name'] = $aryParam['customer_full_name'];
        $aryCustomer['customer_full_name_search'] = $this->encodingUnicode($aryParam['customer_full_name']);
        $aryCustomer['customer_user_name'] = $aryParam['customer_user_name'];
        $aryCustomer['customer_password'] = md5(md5($aryParam['customer_password']));
        $aryCustomer['customer_email'] = $aryParam['customer_email'];
        $aryCustomer['customer_address'] = $aryParam['customer_address'];
        $aryCustomer['customer_home_phone'] = $aryParam['customer_home_phone'];
        $aryCustomer['customer_mobile_phone'] = $aryParam['customer_mobile_phone'];
        $aryCustomer['customer_is_ctv'] = $aryParam['customer_is_ctv'];
        $aryCustomer['customer_yahoo'] = $aryParam['customer_yahoo'];
        $aryCustomer['customer_skype'] = $aryParam['customer_skype'];
        $aryCustomer['customer_of_member_id'] = $aryLogin['member_id'];
        $aryCustomer['customer_of_member_name'] = $aryLogin['member_full_name'];
        $aryCustomer['customer_bank_number'] = $aryParam['customer_bank_number'];
        $aryCustomer['customer_bank_name'] = $aryParam['customer_bank_name'];
        $aryCustomer['customer_zone_id'] = $aryParam['customer_zone_id'];
        $aryCustomer['customer_is_ctv'] = 1;
        $aryLocation = $this->getConfig('location');
        foreach ($aryLocation as $key => $value) {
            if ($value['location_id'] == $aryParam['customer_zone_id']) {
                $locationName = $value['location_name'];
                break;
            }
        }
        $aryCustomer['customer_zone_name'] = $locationName;
        $aryCustomer['customer_join_date'] = date("Y-m-d H:i:s");

        $d = $aryParam['day'];
        $m = $aryParam['month'];
        $y = $aryParam['year'];
        $date = "$y-$m-$d";
        $aryCustomer['customer_date_birthday'] = $date;

//        print_r($aryCustomer);

        $aryError = array();
        $objValidator = new Validator();
        $flag = $objValidator->validateEmpty($aryParam['customer_full_name']);
        if ($flag == true) {
            $aryError['customer_full_name_error'] = _CUSTOMER_EMPTY_FULL_NAME;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_user_name']);
        if ($flag == true) {
            $aryError['customer_user_name_error'] = _CUSTOMER_EMPTY_USER_NAME;
        }
        $username = $aryParam['customer_user_name'];
        $intOk = $this->_objAdminModule->getCustomerUsername($username, $aryCustumerUserName);
        if (count($aryCustumerUserName) > 0) {
            $aryError['customer_user_name_error'] = _CUSTOMER_USER_NAME_ERROR;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_password']);
        if ($flag == true) {
            $aryError['customer_password_error'] = _CUSTOMER_EMPTY_PASSWORD;
        }
        $flag = $objValidator->validateEmpty($aryParam['repassword']);
        if ($flag == true) {
            $aryError['repassword_error'] = _CUSTOMER_EMPTY_RE_PASSWORD;
        }
        if ($aryParam['customer_password'] != $aryParam['repassword']) {
            $aryError['repassword_error'] = _CUSTOMER_PASSWORD_ERROR;
        }
        $checkEmail = $aryParam['customer_email'];
        $intOk = $this->_objAdminModule->getCustomerEmail($checkEmail, $aryCustumerEmail);
        if (count($aryCustumerEmail) > 0) {
            $aryError['customer_email_error'] = _CUSTOMER_EMAIL_ERROR;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_email']);
        if ($flag == true) {
            $aryError['customer_email_error'] = _CUSTOMER_EMPTY_EMAIL;
        } else {
            $flag = $objValidator->validateMail($aryParam['customer_email']);
            if ($flag == false) {
                $aryError['customer_email_error'] = _CUSTOMER_ERROR_EMAIL;
            }
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_zone_id']);
        if ($flag == true) {
            $aryError['customer_zone_id_error'] = _CUSTOMER_EMPTY_PROVINCE;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_mobile_phone']);
        if ($flag == false) {
            $flag = $objValidator->validatePhone($aryParam['customer_mobile_phone']);
            if ($flag == false) {
                $aryError['customer_mobile_phone_error'] = _CUSTOMER_ERROR_FORMAT_PHONE;
            }
        } else {
            $aryError['customer_mobile_phone_error'] = _CUSTOMER_EMPTY_MOBILE_PHONE;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_home_phone']);
        if ($flag == false) {
            $flag = $objValidator->validatePhone($aryParam['customer_home_phone']);
            if ($flag == false) {
                $aryError['customer_home_phone_error'] = _CUSTOMER_ERROR_FORMAT_PHONE;
            }
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_address']);
        if ($flag == true) {
            $aryError['customer_address_error'] = _CUSTOMER_EMPTY_ADRESS;
        }
        //validate birthday
        $flag = $objValidator->validateEmpty($aryParam['day']);
        if ($flag == true) {
            $aryError['customer_birthday_error'] = _CUSTOMER_EMPTY_DAY;
        }
        $flag = $objValidator->validateEmpty($aryParam['month']);
        if ($flag == true) {
            $aryError['customer_birthday_error'] = _CUSTOMER_EMPTY_MONTH;
        }
        $flag = $objValidator->validateEmpty($aryParam['year']);
        if ($flag == true) {
            $aryError['customer_birthday_error'] = _CUSTOMER_EMPTY_YEAR;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_bank_number']);
        if ($flag == false) {
            $flag = $objValidator->validateNumber($aryParam['customer_bank_number']);
            if ($flag == false) {
                $aryError['customer_bank_number_error'] = _CUSTOMER_ERROR_BANK_NUMBER;
            }
        }

        $flag = $objValidator->validateEmpty($aryParam['customer_yahoo']);
        if ($flag == true) {
            $aryError['customer_yahoo_error'] = _CUSTOMER_EMPTY_YAHOO;
        }

        $aryResult = array();
        if (count($aryError) > 0) {
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            $aryResult['messageError'] = _CUSTOMER_MESSAGE_ERROR;
            echo json_encode($aryResult);
            return;
        }
        $intOk = $this->_objAdminModule->saveCustomerData($aryCustomer, $customerId);
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _CUSTOMER_REGISTER_SUCCESS;
        echo json_encode($aryResult);
    }

    public function getMyProfit() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryResult = array();
        $aryResult['intOk'] = 1;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'kd_get_my_profit');
        echo json_encode($aryResult);
    }

    public function addMyProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $aryError = $this->validateAddMyProduct($aryParam);
        if (count($aryError) > 0) {
            $aryResult = array();
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            echo json_encode($aryResult);
            return;
        }

        $aryLogin = $this->getSession('login');
        $aryLocation = $this->getConfig('location');
        $aryCustomer = array();
        $aryCustomer['customer_full_name'] = $aryParam['customer_full_name'];
        $aryCustomer['customer_full_name_search'] = $this->encodingUnicode($aryParam['customer_full_name']);
        $aryCustomer['customer_email'] = $aryParam['customer_email'];
        $aryCustomer['customer_zone_id'] = $aryParam['customer_zone_id'];
        foreach ($aryLocation as $key => $value) {
            if ($value['location_id'] == $aryParam['customer_zone_id']) {
                $aryCustomer['customer_zone_name'] = $value['location_name'];
                break;
            }
        }

        $aryCustomer['customer_mobile_phone'] = $aryParam['customer_mobile_phone'];
        $aryCustomer['customer_home_phone'] = $aryParam['customer_home_phone'];
        $aryCustomer['customer_yahoo'] = $aryParam['customer_yahoo'];
        $aryCustomer['customer_skype'] = $aryParam['customer_skype'];
        $aryCustomer['customer_address'] = $aryParam['customer_address'];
        $day = $aryParam['day'];
        $month = $aryParam['month'];
        $year = $aryParam['year'];
        if (isset($day) && isset($month) && isset($year)) {
            $aryCustomer['customer_date_birthday'] = "$year-$month-$day";
        }
        $aryCustomer['customer_is_customer'] = 1;
        $aryCustomer['customer_of_member_id'] = $aryLogin['member_id'];
        $aryCustomer['customer_of_member_name'] = $aryLogin['member_full_name'];
        $aryCustomer['customer_join_date'] = date("Y-m-d H:i:s");
        $aryProduct = array();
        if ($aryParam['customer_id'] != '') {
            $aryProduct['customer_product_customer_id'] = $aryParam['customer_id'];
        } else {
            $intOk = $this->_objAdminModule->saveCustomerData($aryCustomer, $customerId);
            $aryProduct['customer_product_customer_id'] = $customerId;
        }
        $aryProduct['customer_product_product_name'] = $aryParam['customer_product_product_name'];
        $aryProduct['customer_product_product_name_search'] = $this->encodingUnicode($aryParam['customer_product_product_name']);
        $aryProduct['customer_product_kd_id'] = $aryLogin['member_id'];
        $aryProduct['customer_product_in_price'] = $aryParam['customer_product_in_price'];
        $aryProduct['customer_product_out_price'] = $aryParam['customer_product_out_price'];
        $aryProduct['customer_product_number'] = $aryParam['customer_product_number'];
        $aryProduct['customer_product_is_customer'] = 1;
        $aryProduct['customer_product_unit'] = $aryParam['customer_product_unit'];
        $aryProduct['customer_product_transport'] = $aryParam['customer_product_transport'];
        $aryProduct['customer_product_services'] = $aryParam['customer_product_services'];
        $aryProduct['customer_product_disparity'] = $aryParam['customer_product_disparity'];
        $aryProduct['customer_product_date_send'] = date("Y-m-d H:i:s");
        $aryProduct['customer_product_date_process'] = date("Y-m-d H:i:s");
        $aryProduct['customer_product_month_process'] = intval(date("m"));
        $aryProduct['customer_product_year_process'] = date("Y");
        $aryProduct['customer_product_total_price'] = (($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * $aryParam['customer_product_number']);
        $aryProduct['customer_product_is_tax'] = ((($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * $aryParam['customer_product_number']) * 0.25);
        $profit = (($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * 0.75);
        $totalProfit = $profit * $aryParam['customer_product_number'];
        if (isset($aryParam['customer_product_transport']) && is_numeric($aryParam['customer_product_transport'])) {

            $totalProfit = $totalProfit - $aryParam['customer_product_transport'];
        }
        if (isset($aryParam['customer_product_services']) && is_numeric($aryParam['customer_product_services'])) {

            $totalProfit = $totalProfit - $aryParam['customer_product_services'];
        }
        $aryProduct['customer_product_total_profit'] = $totalProfit;

        $intOk = $this->_objAdminModule->insertProductCustomer($aryProduct);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _CUSTOMER_PRODUCT_SAVE_SUCCESS;
        $aryResult['aryError'] = $aryError;
        echo json_encode($aryResult);
    }

    public function searchCustomerInfo() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $aryConditions = array();
        $aryConditions['customer_full_name_search'] = $this->encodingUnicode(trim(strip_tags($aryParam['customer_full_name_search'])));
        $aryConditions['customer_mobile_phone_search'] = trim(strip_tags($aryParam['customer_mobile_phone_search']));
        $aryConditions['current_page'] = $this->getParam('page');
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $intOk = $this->_objAdminModule->searchCustomerInfoData($aryConditions, $aryCustomerData);
        $this->setActionJSPaging("AdminController.searchCustomerInfo(");
        $strPaging = $this->AjaxPagination($aryCustomerData['paging']);
        $this->assign('strPaging', $strPaging);
        $this->assign('aryCustomerData', $aryCustomerData['data']);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'kd_search_list_customer');
        echo json_encode($aryResult);
    }

    public function searchMyCustomerInfo() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $aryConditions = array();
        $aryConditions['customer_full_name_search'] = $this->encodingUnicode(trim(strip_tags($aryParam['customer_full_name_search'])));
        $aryConditions['customer_mobile_phone_search'] = trim(strip_tags($aryParam['customer_mobile_phone_search']));
        $aryConditions['current_page'] = $this->getParam('page');
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $intOk = $this->_objAdminModule->searchCustomerInfoData($aryConditions, $aryCustomerData);
        $aryLogin = $this->getSession('login');
        $memberId = $aryLogin['member_id'];
        $aryConditions['customer_product_kd_id'] = $memberId;
        $this->_objAdminModule->getMyCustomerProduct($aryConditions, $aryProductData);
        foreach ($aryProductData as $key => $value) {
            $aryTotalProduct[$value['customer_product_customer_id']]['total_product']+=$value['customer_product_number'];
        }
        $this->assign('aryTotalProduct', $aryTotalProduct);
        $this->setActionJSPaging("AdminController.searchMyCustomerInfo(");
        $strPaging = $this->AjaxPagination($aryCustomerData['paging']);
        $this->assign('strPaging', $strPaging);
        $this->assign('aryCustomerData', $aryCustomerData['data']);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'kd_search_list_my_customer');
        echo json_encode($aryResult);
    }

    public function viewDetailSearchCustomer() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $strCustomerId = $this->getParam('customerId');
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($strCustomerId, $aryCustomerInfo);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryBirthDay = explode("-", $aryCustomerInfo[0]['customer_date_birthday']);
        $aryCustomerInfo[0]['day'] = intval($aryBirthDay[2]);
        $aryCustomerInfo[0]['month'] = intval($aryBirthDay[1]);
        $aryCustomerInfo[0]['year'] = intval($aryBirthDay[0]);
        $aryResult['data'] = $aryCustomerInfo[0];
        echo json_encode($aryResult);
    }

    public function searchMyProfit() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryParam = $this->getAllPostParams();
        $aryLogin = $this->getSession('login');
        $memberId = $aryLogin['member_id'];
        $aryConditions = array();
        $aryConditions['customer_product_month_process'] = $aryParam['customer_product_month_process'];
        $aryConditions['customer_product_year_process'] = $aryParam['customer_product_year_process'];
        $aryConditions['customer_product_kd_id'] = $memberId;
        $aryConditions['current_page'] = $this->getParam('page');
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $intOk = $this->_objAdminModule->searchMyProfitData($aryConditions, $aryMyProduct);
        $this->assign('month', $aryParam['customer_product_month_process']);
        $this->assign('year', $aryParam['customer_product_year_process']);
        $this->assign('aryMyProduct', $aryMyProduct['data']);
        $this->setActionJSPaging("AdminController.searchMyProfit(");
        $strPaging = $this->AjaxPagination($aryMyProduct['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'kd_list_my_product');
        echo json_encode($aryResult);
    }

    public function editMyProductAndMyCustomer() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $strCustomerId = $this->getParam('customerId');
        $productId = $this->getParam('productId');
        $aryLocation = $this->getConfig('location');
        $intOk = $this->_objAdminModule->getCustomerProductById($productId, $aryProductData);
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($strCustomerId, $aryCustomerInfo);
        $this->assign('aryCustomerInfo', $aryCustomerInfo[0]);
        $this->assign('aryProductData', $aryProductData[0]);
        $aryBirthday = explode("-", $aryCustomerInfo[0]['customer_date_birthday']);
        $date = $aryBirthday[2];
        $month = $aryBirthday[1];
        $year = $aryBirthday[0];
        $this->assign('aryLocation', $aryLocation);
        $this->assign('customerId', $strCustomerId);
        $this->assign('productId', $productId);
        $this->assign('date', $date);
        $this->assign('month', $month);
        $this->assign('year', $year);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'kd_view_detail_my_product');
        echo json_encode($aryResult);
    }

    public function editMyProduct() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $type = $this->getParam('type');
        $productId = $this->getParam('productId');
        $customerId = $this->getParam('customerId');
        $aryLogin = $this->getSession('login');
        $aryParam = $this->getAllPostParams();
        $aryCustomerData = array();
        $aryCustomerData['customer_full_name'] = $aryParam['customer_full_name'];
        $aryCustomerData['customer_email'] = $aryParam['customer_email'];
        $aryCustomerData['customer_zone_id'] = $aryParam['customer_zone_id'];
        $aryCustomerData['customer_mobile_phone'] = $aryParam['customer_mobile_phone'];
        $aryCustomerData['customer_home_phone'] = $aryParam['customer_home_phone'];
        $aryLocation = $this->getConfig('location');
        foreach ($aryLocation as $key => $value) {
            if ($value['location_id'] == $aryParam['customer_zone_id']) {
                $aryCustomerData['customer_zone_name'] = $value['location_name'];
                break;
            }
        }
        $aryCustomerData['customer_yahoo'] = $aryParam['customer_yahoo'];
        $aryCustomerData['customer_skype'] = $aryParam['customer_skype'];
        $aryCustomerData['customer_address'] = $aryParam['customer_address'];
        $day = $aryParam['day'];
        $month = $aryParam['month'];
        $year = $aryParam['year'];
        $aryCustomerData['customer_date_birthday'] = "$year-$month-$day";

        //product
        $aryProduct = array();
        $aryProduct['customer_product_product_name'] = $aryParam['customer_product_product_name'];
        $aryProduct['customer_product_product_name_search'] = $this->encodingUnicode($aryParam['customer_product_product_name']);
        $aryProduct['customer_product_kd_id'] = $aryLogin['member_id'];
        $aryProduct['customer_product_in_price'] = $aryParam['customer_product_in_price'];
        $aryProduct['customer_product_out_price'] = $aryParam['customer_product_out_price'];
        $aryProduct['customer_product_number'] = $aryParam['customer_product_number'];
        $aryProduct['customer_product_is_customer'] = 1;
        $aryProduct['customer_product_unit'] = $aryParam['customer_product_unit'];
        $aryProduct['customer_product_transport'] = $aryParam['customer_product_transport'];
        $aryProduct['customer_product_services'] = $aryParam['customer_product_services'];
        $aryProduct['customer_product_disparity'] = $aryParam['customer_product_disparity'];
        $aryProduct['customer_product_total_price'] = (($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * $aryParam['customer_product_number']);
        $aryProduct['customer_product_is_tax'] = ((($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * $aryParam['customer_product_number']) * 0.25);
        $profit = (($aryParam['customer_product_out_price'] - $aryParam['customer_product_in_price']) * 0.75);
        $totalProfit = $profit * $aryParam['customer_product_number'];
        if (isset($aryParam['customer_product_transport']) && is_numeric($aryParam['customer_product_transport'])) {

            $totalProfit = $totalProfit - $aryParam['customer_product_transport'];
        }
        if (isset($aryParam['customer_product_services']) && is_numeric($aryParam['customer_product_services'])) {

            $totalProfit = $totalProfit - $aryParam['customer_product_services'];
        }
        $aryProduct['customer_product_total_profit'] = $totalProfit;

        $aryConfigCustomer = array(
            array(
                'keyword' => 'where',
                'field' => 'customer_id',
                'math' => '=',
                'value' => $customerId
            )
        );
        $aryConfigProduct = array(
            array(
                'keyword' => 'where',
                'field' => 'customer_product_id',
                'math' => '=',
                'value' => $productId
            )
        );
        switch ($type) {
            case 1:
                $intOk = $this->_objAdminModule->updateMyProduct($aryConfigProduct, $aryProduct);
                $message = _CUSTOMER_PRODUCT_EDIT_CUSSECC;
                break;

            case 2:
                $intOk = $this->_objAdminModule->updateMyCustomerInfo($aryConfigCustomer, $aryCustomerData);
                $message = _CUSTOMER_EDIT_INFO_SUCCESS;
                break;

            case 3:
                $intOk = $this->_objAdminModule->updateMyProduct($aryConfigProduct, $aryProduct);
                $intOk = $this->_objAdminModule->updateMyCustomerInfo($aryConfigCustomer, $aryCustomerData);
                $message = _CUSTOMER_EDIT_PRODUCT_AND_INFO_SUCCESS;
                break;
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = $message;
        echo json_encode($aryResult);
    }

    public function getMyCustomer() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $aryConditions = array();
        $aryConditions['current_page'] = $this->getParam('page');
        $aryConditions['record_per_page'] = $this->getConfig('ctv_limit');
        $intOk = $this->_objAdminModule->searchCustomerInfoData($aryConditions, $aryCustomerData);
        $aryLogin = $this->getSession('login');
        $memberId = $aryLogin['member_id'];
        $aryConditions['customer_product_kd_id'] = $memberId;
        $this->_objAdminModule->getMyCustomerProduct($aryConditions, $aryProductData);
        foreach ($aryProductData as $key => $value) {
            $aryTotalProduct[$value['customer_product_customer_id']]['total_product']+=$value['customer_product_number'];
        }
        $this->assign('aryTotalProduct', $aryTotalProduct);
        $this->setActionJSPaging("AdminController.getMyCustomer(");
        $strPaging = $this->AjaxPagination($aryCustomerData['paging']);
        $this->assign('strPaging', $strPaging);
        $this->assign('aryCustomerData', $aryCustomerData['data']);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'kd_list_my_customer');
        echo json_encode($aryResult);
    }

    public function viewDetailMyCustomer() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $customerId = $this->getParam('customerId');
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($customerId, $aryCustomerInfo);
        $aryLogin = $this->getSession('login');
        $memberId = $aryLogin['member_id'];
        $aryConditions = array();
        $aryConditions['customer_product_customer_id'] = $customerId;
        $aryConditions['customer_product_kd_id'] = $memberId;
        $this->_objAdminModule->getMyCustomerProductByCusId($aryConditions, $aryCustomerProduct);
//        print_r($aryCustomerProduct);
        $this->assign('aryCustomer', $aryCustomerInfo[0]);
        $this->assign('aryMyProduct', $aryCustomerProduct);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'kd_view_detail_my_customer');
        echo json_encode($aryResult);
    }

    public function showEditCustomerCtv() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();
        $customerCtvId = $this->getParam('customerCtvId');
        $intOk = $this->_objAdminModule->getCustomerInfoByListId($customerCtvId, $aryCustomerInfo);
        $aryCustomer = array();
        $aryCustomer['customer_full_name_ctv'] = $aryCustomerInfo[0]['customer_full_name'];
        $aryCustomer['customer_email_ctv'] = $aryCustomerInfo[0]['customer_email'];
        $aryCustomer['customer_mobile_phone_cvt'] = $aryCustomerInfo[0]['customer_mobile_phone'];
        $aryCustomer['customer_home_phone_ctv'] = $aryCustomerInfo[0]['customer_home_phone'];
        $aryCustomer['customer_yahoo_ctv'] = $aryCustomerInfo[0]['customer_yahoo'];
        $aryCustomer['customer_skype_ctv'] = $aryCustomerInfo[0]['customer_skype'];
        $aryCustomer['customer_gender_ctv'] = $aryCustomerInfo[0]['customer_gender'];
        $aryBirthday = explode("-", $aryCustomerInfo[0]['customer_date_birthday']);
        $aryCustomer['day_ctv'] = $aryBirthday[2];
        $aryCustomer['month_ctv'] = $aryBirthday[1];
        $aryCustomer['year_ctv'] = $aryBirthday[0];
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['data'] = $aryCustomer;
        echo json_encode($aryResult);
    }

    public function showEditCategoryContent() {
        $categoryId = $this->getParam('categoryId');
        $intOk = $this->_objAdminModule->getCategoryContent($categoryId, $aryContent);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['data'] = $aryContent[0];
        echo json_encode($aryResult);
    }

    public function updateCategoryContent() {
        $aryParam = $this->getAllPostParams();
        $categoryId = $aryParam['category_content_category_id'];
        $aryData = array();
        $aryData['category_title_header'] = $aryParam['input_category_title_header'];
        $aryData['category_keyword'] = $aryParam['input_category_keyword'];
        $aryData['category_description'] = $aryParam['input_category_description'];
        $aryData['category_content'] = $aryParam['category_content_content'];
        $aryData['category_content_h1'] = $aryParam['category_content_h1'];
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'category_id',
                'math' => '=',
                'value' => $categoryId
            )
        );
        $intOk = $this->_objAdminModule->updateCategoryContent($aryConfig, $aryData);

        $this->setFlagCategoryCache($categoryId);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = 'Nội dung danh mục đã được cập nhật';

        echo json_encode($aryResult);
    }

    public function getIntroduction() {
        $aryIntroduction = array();
        $aryData = array();
        $intOk = $this->_objAdminModule->getIntroductionData($aryIntroduction);
        $aryResult = array();
        $this->assign('aryIntroduction', $aryIntroduction);
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'intro-list-intro');
        echo json_encode($aryResult);
    }

    public function getIntroductionById() {
        $introductionId = $this->getParam('introductionId');
        $intOk = $this->_objAdminModule->getIntroductionDataById($introductionId, $aryIntroduction);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['data'] = $aryIntroduction[0];
        echo json_encode($aryResult);
    }

    public function saveIntroduction() {
        $aryData = $this->getAllPostParams();
        $type = $aryData['into_flag'];
        $aryError = array();
        $aryError = $this->validateIntro($aryData);
        $aryResult = array();
        if (count($aryError) > 0) {
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            $aryResult['message'] = 'Vui lòng nhập đầy đủ nội dung.';
            echo json_encode($aryResult);
            return;
        }

        $aryIntroduction = array();
        $aryIntroduction['mc_company_common_title'] = $aryData['common_gioithieu_title'];
        $aryIntroduction['mc_company_commom_link'] = $aryData['common_gioithieu_link'];
        $aryIntroduction['mc_company_common_content'] = $aryData['common_gioi_thieu'];
        $aryIntroduction['mc_company_common_create_date'] = date('Y-m-d H:i:s');
        switch ($type) {
            case "add":
                $intOk = $this->_objAdminModule->insertIntroductionData($aryIntroduction);
                $aryResult['message'] = 'Nội dung đã được lưu';
                break;
            case "edit":
                $aryCondition = array(
                    array(
                        'keyword' => 'where',
                        'field' => 'mc_company_common_id',
                        'math' => '=',
                        'value' => $aryData['mc_company_common_id']
                    )
                );
                $intOk = $this->_objAdminModule->updateIntroduction($aryCondition, $aryIntroduction);
                $aryResult['message'] = 'Nội dung đã được cập nhật';
                break;
        }

        $aryResult['intOk'] = $intOk;
        $aryResult['type'] = $type;
        echo json_encode($aryResult);
    }

    public function validateIntro($aryData) {
        $aryError = array();
        $objValidator = new Validator();
        $flag = $objValidator->validateEmpty($aryData['common_gioithieu_title']);
        if ($flag == true) {
            $aryError['common_gioithieu_title_error'] = 'Bạn chưa nhập tiêu đề.';
        }
        $flag = $objValidator->validateEmpty($aryData['common_gioithieu_link']);
        if ($flag == true) {
            $aryError['common_gioithieu_link_error'] = 'Bạn chưa nhập link.';
        }
        $flag = $objValidator->validateEmpty($aryData['common_gioi_thieu']);
        if ($flag == true) {
            $aryError['common_gioi_thieu_error'] = 'Bạn chưa nhập nội dung.';
        }
        return $aryError;
    }

    public function deleteIntroduction() {
        $introductionId = $this->getParam('introductionId');
        $aryCondition = array(
            array(
                'keyword' => 'where',
                'field' => 'mc_company_common_id',
                'math' => '=',
                'value' => $introductionId
            )
        );
        $aryData = array();
        $aryData['mc_company_common_del_flag'] = 1;
        $intOk = $this->_objAdminModule->updateIntroduction($aryCondition, $aryData);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = 'Nội dung đã được xóa';
        echo json_encode($aryResult);
    }

    public function saveSupportOnline() {
        $aryError = array();
        $objValidator = new Validator();
        $aryParam = $this->getAllPostParams();
        $aryName = $aryParam['support_name'];
        $aryNickYahoo = $aryParam['support_yahoo'];
        $aryNickSkyper = $aryParam['support_skyper'];
        $aryPhone = $aryParam['support_mobile'];

        $n = 0;
        $m = 0;
        $i = 0;

        foreach ($aryName as $key => $value) {
            if ($objValidator->validateEmpty($value) == true) {
                $i++;
            } else {
                if ($objValidator->validateEmpty($aryNickYahoo[$key]) == true && $objValidator->validateEmpty($aryNickSkyper[$key]) == true) {
                    $aryError[] = 'Bạn chưa nhập nick hỗ trợ cho ' . $aryName[$key];
                    break;
                }
            }
        }

        if ($i == count($aryName)) {
            $aryError[] = 'Bạn chưa nhập tên người hỗ trợ.';
        }

        foreach ($aryNickYahoo as $key => $value) {
            if ($objValidator->validateEmpty($value) == true) {
                $n++;
            }
        }

        foreach ($aryNickSkyper as $key => $value) {
            if ($objValidator->validateEmpty($value) == true) {
                $m++;
            }
        }

        foreach ($aryPhone as $key2 => $value) {
            if ($objValidator->validateEmpty($aryName[$key2]) == false && $objValidator->validateEmpty($value) == true) {
                $aryError[] = 'Bạn chưa nhập số điện thoại cho ' . $aryName[$key2];
                break;
            }
            if ($objValidator->validateEmpty($value) == false) {
                if ($objValidator->validatePhone($value) == false && $objValidator->validateEmpty($aryName[$key2]) == false) {
                    $aryError[] = 'Số điện thoại của ' . $aryName[$key2] . ' không đúng.';
                    break;
                }
            }
        }
        $aryResult = array();
        if (count($aryError) > 0) {
            $intOk = -2;
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = join("<br>", $aryError);
            echo json_encode($aryResult);
            return;
        }

        foreach ($aryName as $key => $value) {
            if (strlen($value) > 0) {
                $aryData = array();
                $aryData['support_online_name'] = $value;
                $aryData['support_online_yahoo'] = $aryNickYahoo[$key];
                $aryData['support_online_skyper'] = $aryNickSkyper[$key];
                $aryData['support_online_mobile'] = $aryPhone[$key];
                $intOk = $this->_objAdminModule->saveSupportOnline($aryData);
            }
        }

        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = 'Danh sách hỗ trợ đã được lưu';
        echo json_encode($aryResult);
    }

    public function showListSupportOnline() {
        $aryParam = $this->getAllPostParams();
        $intOk = $this->_objAdminModule->getSupportOnlineData($aryData);
        $aryResult = array();
        $this->assign('arySupportOnline', $aryData);
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'list_support_online');

        echo json_encode($aryResult);
    }

    public function deleteSupportOnline() {
        $onlineId = $this->getParam('onlineId');
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'support_online_id',
                'value' => $onlineId,
                'math' => '='
            )
        );

        $aryDelete = array();
        $aryDelete['support_online_del_flag'] = 1;
        $intOk = $this->_objAdminModule->updateSupportOnline($aryConfig, $aryDelete);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = 'Thông tin hỗ trợ đã được xóa';
        echo json_encode($aryResult);
    }

    public function updateProductCustomerOrder() {
        $customerDetailId = $this->getParam('customerDetailId');
        $customerOrderId = $this->getParam('customerOrderId');
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'product_order_detail_id',
                'value' => $customerDetailId,
                'math' => '='
            )
        );
        $aryData = array();
        $aryData['product_order_product_customer_id'] = $customerOrderId;
        $aryData['product_order_active'] = 1;
        $aryData['product_order_process_date'] = date('Y-m-d H:i:s');
        $aryCreator = $this->getSession('login');
        $aryData['product_order_creator_id'] = $aryCreator['member_id'];
        $aryData['product_order_creator_name'] = $aryCreator['member_full_name'];
        $aryData['product_order_create_date_date'] = date('d');
        $aryData['product_order_create_date_month'] = date('m');
        $aryData['product_order_create_date_year'] = date('Y');
        $intOk = $this->_objAdminModule->updateProductOrder($aryConfig, $aryData);
        if ($intOk == 1) {
            $aryOrderUpdate = array();
            $aryOrderUpdate['order_detail_is_process'] = 1;
            $aryOrderUpdate['order_detail_comment'] = $this->getPostParam('orderComment');
            $aryOrderUpdate['order_detail_process_date'] = date('Y-m-d H:i:s');
            $aryConfig = array(
                array(
                    'keyword' => 'where',
                    'field' => 'order_detail_id',
                    'math' => '=',
                    'value' => $customerDetailId
                )
            );
            $intOk = $this->_objAdminModule->updateStatusOrder($aryOrderUpdate, $aryConfig);
        }
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _ORDER_PROCESS_SUCCESS;
        echo json_encode($aryResult);
    }

    public function showAddNewProductOrder() {
        $categoryId = 0;
        $aryCategory = array();
        $this->_objAdminModule->getCategory($aryCategory);
        $this->assign('aryCategory', $aryCategory);
        $aryResult = array();
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'order_form_add_new_order');
        echo json_encode($aryResult);
    }

    public function searchProductOrder() {
        $this->checkCookieLogin();
        $this->checkSessionLogin();

        $intOk = 1;

        $aryParam = $this->getAllPostParams();

        $productName = $aryParam['search_product_order_name'];

        $parentCategory = $aryParam['search_product_category_id'];

        if ($productName == '') {

            $strError = _SEARCH_EMPTY_KEYWORD;

            $intOk = -2;
        }

        if ($intOk == 1) {

            $aryChildCategory = array();
            if ($parentCategory != 0) {
                $aryChildCategory = $this->_objAdminModule->getCategoryChildPath($parentCategory);
                array_push($aryChildCategory, $parentCategory);
            }
            if (isset($aryChildCategory[0])) {
                $listCatId = implode(",", $aryChildCategory);
            }
            $orderType = $this->getParam('orderType');
            $page = $this->getParam('page');
            $aryConditions = array();
            $aryConditions['product_name'] = $this->encodingUnicode(strip_tags($productName));
            $aryConditions['record_per_page'] = 2;
            $aryConditions['current_page'] = $page;

            if ($orderType == 'date-up') {
                $aryConditions['field'] = 'product_updated_date';
                $aryConditions['order'] = 'ASC';
            } else if ($orderType == 'date-down') {
                $aryConditions['field'] = 'product_updated_date';
                $aryConditions['order'] = 'DESC';
            } else if ($orderType == 'price-up') {
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'ASC';
            } else if ($orderType == 'price-down') {
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'DESC';
            } else if ($orderType == 'id-down') {
                $aryConditions['field'] = 'product_id';
                $aryConditions['order'] = 'DESC';
            } else if ($orderType == 'id-up') {
                $aryConditions['field'] = 'product_id';
                $aryConditions['order'] = 'ASC';
            }


            $intOk = $this->_objAdminModule->searchProductData($aryConditions, $listCatId, $aryProduct);

            $this->setActionJSPaging("AdminController.searchProductOrder('$orderType',");

            $strPaging = $this->AjaxPagination($aryProduct['paging']);

            $this->assign('perProductAdd', $aryParam['perProductAdd']);
            $this->assign('perProductEdit', $aryParam['perProductEdit']);
            $this->assign('perProductDelete', $aryParam['perProductDelete']);
            $this->assign('isMaster', $aryParam['isMaster']);

            $this->assign('orderType', $orderType);

            $this->assign('page', $page);

            $this->assign('strPaging', $strPaging);

            $this->assign('aryProduct', $aryProduct['data']);
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['strError'] = $strError;
        $aryResult['searchContent'] = $this->getViewTemplate('admin/blackadmin', 'product_order_search_result');
        echo json_encode($aryResult);
    }

    public function getProcessProductOrder() {
        $listProductOrder = $this->getParam('listProductOrder');
        $aryProductOrder = explode(",", $listProductOrder);
        foreach ($aryProductOrder as $key => $value) {
            if ($aryProductOrder[$key] == '') {
                unset($aryProductOrder[$key]);
            }
        }
        $listProduct = implode(",", $aryProductOrder);
        $intOk = $this->_objAdminModule->getProductByListId($listProduct, $aryProductOrder);
        $this->assign('aryProductOrder', $aryProductOrder);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product_list_product_order');
        echo json_encode($aryResult);
    }

    public function searchCustomerOrder() {
        $aryParam = $this->getAllPostParams();
        $aryConditions = array();
        $aryConditions['order_detail_search_name'] = trim(strip_tags($this->encodingUnicode($aryParam['customer_order_full_name_search'])));
        $aryConditions['order_detail_phone_number'] = trim(strip_tags($aryParam['customer_order_mobile_search']));
        $aryConditions['order_detail_email'] = trim(strip_tags($aryParam['customer_order_email_search']));
        $aryConditions['current_page'] = $this->getParam('page');
        $aryConditions['record_per_page'] = 1;
//        print_r($aryConditions);
        $intOk = $this->_objAdminModule->searchCustomerOrderDetail($aryConditions, $aryCustomer, 'order');
        $this->assign('aryCustomer', $aryCustomer['data']);
        $this->setActionJSPaging("AdminController.searchCustomerOrder(");
        $strPaging = $this->AjaxPagination($aryCustomer['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'product_order_list_search_customer');
        echo json_encode($aryResult);
    }

    public function getCustomerOrderDetail() {
        $customerId = $this->getParam('customerId');
        $intOk = $this->_objAdminModule->getOrderDetailById($customerId, $aryCustomer);
        $aryJsonForm = array();
        $aryJsonForm['order_detail_full_name'] = $aryCustomer[0]['order_detail_full_name'];
        $aryJsonForm['order_detail_phone_number'] = $aryCustomer[0]['order_detail_phone_number'];
        $aryJsonForm['order_detail_email'] = $aryCustomer[0]['order_detail_email'];
        $aryJsonForm['order_detail_yahoo'] = $aryCustomer[0]['order_detail_yahoo'];
        $aryJsonForm['order_detail_address'] = $aryCustomer[0]['order_detail_address'];
        $aryJsonForm['order_detail_address_delivery'] = $aryCustomer[0]['order_detail_address_delivery'];
        $aryJsonForm['order_detail_method_delivery'] = $aryCustomer[0]['order_detail_method_delivery'];
        $aryJsonForm['order_detail_method_payment'] = $aryCustomer[0]['order_detail_method_payment'];
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['data'] = $aryJsonForm;
        echo json_encode($aryResult);
    }

    public function quickEditProduct() {
        $productId = $this->getParam('productId');
        $type = $this->getParam('type');
        $orderId = $this->getParam('orderId');
        $aryParam = $this->getAllPostParams();
        if (($type == 'order' || $type == 'orderandproduct') && $orderId > 0) {
            $aryConfigOrder = array(
                array(
                    'keyword' => 'where',
                    'field' => 'product_order_id',
                    'math' => '=',
                    'value' => $orderId
                )
            );

            $aryProductOrder = array();
            if (isset($aryParam['product_title'])) {
                $aryProductOrder['product_order_product_name'] = $aryParam['product_title'];
                $aryProductOrder['product_order_product_name_filter'] = $aryParam['product_title_filter'];
            }
            if (isset($aryParam['product_price_vnd_in'])) {
                $aryProductOrder['product_order_product_price_in'] = $aryParam['product_price_vnd_in'];
            }
            if (isset($aryParam['product_price_vnd'])) {
                $aryProductOrder['product_order_product_price'] = $aryParam['product_price_vnd'];
            }
            if (isset($aryParam['product_order_total_product'])) {
                $aryProductOrder['product_order_total_product'] = $aryParam['product_order_total_product'];
                $aryProductOrder['product_order_total_price'] = $aryParam['product_order_total_product'] * $aryParam['product_price_vnd'];
            }
            if (isset($aryParam['product_order_product_unit'])) {
                $aryProductOrder['product_order_product_unit'] = $aryParam['product_order_product_unit'];
            }
            if (isset($aryParam['product_category_id'])) {
                $aryProductOrder['product_order_category_id'] = $aryParam['product_category_id'];
            }
            if (isset($aryParam['product_category_name'])) {
                $aryProductOrder['product_order_category_name'] = $aryParam['product_category_name'];
                $aryProductOrder['product_order_category_filter'] = $this->filterUnicode($aryParam['product_category_name']);
            }
            $aryProductOrder['product_order_last_update_date'] = date('Y-m-d H:i:s');
            $intOk = $this->_objAdminModule->updateProductOrder($aryConfigOrder, $aryProductOrder);
        }

        if ($type == 'orderandproduct' || $type == 'product') {
            $aryConfig = array(
                array(
                    'keyword' => 'where',
                    'field' => 'product_id',
                    'value' => $productId,
                    'math' => '='
                )
            );

            $aryUpdate = array();
            $aryUpdate['product_title'] = $aryParam['product_title'];
            $aryUpdate['product_title_filter'] = $this->filterUnicode($aryParam['product_title']);
            $aryUpdate['product_price_vnd'] = $aryParam['product_price_vnd'];
            $aryUpdate['product_price_vnd_in'] = $aryParam['product_price_vnd_in'];
            $intOk = $this->_objAdminModule->updateProduct($aryUpdate, $aryConfig);
        }
        $aryProduct = array();
        $this->assign('aryProduct', $aryParam);
        $this->assign('product_id', $productId);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['type'] = $type;
        $aryResult['product_id'] = $productId;
        $aryResult['messageError'] = "Cập nhật sản phẩm lỗi";
        if ($type == 'order' || $type == 'orderandproduct') {
            $aryResult['productContent'] = $this->getViewTemplate('admin/blackadmin', 'order_update_product_order_success');
        } else if ($type == 'product') {
            $aryResult['productContent'] = $this->getViewTemplate('admin/blackadmin', 'order_update_product_success');
        }

        echo json_encode($aryResult);
    }

    public function saveNewProductOrder() {
        $aryParam = $this->getAllPostParams();
        $aryError = $this->validateAddProductOrder($aryParam);
        if ($aryParam['listProductOrder'] == '') {
            $aryRestult = array();
            $aryRestult['intOk'] = -3;
            $aryRestult['messageError'] = _ORDER_EMPTY_PRODUCT;
            echo json_encode($aryRestult);
            return;
        }
        if (count($aryError) > 0) {
            $aryResult = array();
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            echo json_encode($aryResult);
            return;
        }
        $processStatus = $this->getParam('processStatus');
        $aryCustomerOrder = array();
        $aryCustomerOrder['order_detail_cookie_id'] = 'manage';
        $aryCustomerOrder['order_detail_full_name'] = $aryParam['order_detail_full_name'];
        $aryCustomerOrder['order_detail_search_name'] = $this->encodingUnicode($aryParam['order_detail_full_name']);
        $aryCustomerOrder['order_detail_address'] = $aryParam['order_detail_address'];
        $aryCustomerOrder['order_detail_address_delivery'] = $aryParam['order_detail_address_delivery'];
        $aryCustomerOrder['order_detail_phone_number'] = $aryParam['order_detail_phone_number'];
        $aryCustomerOrder['order_detail_yahoo'] = $aryParam['order_detail_yahoo'];
        $aryCustomerOrder['order_detail_email'] = $aryParam['order_detail_email'];
        $aryCustomerOrder['order_detail_is_process'] = $processStatus;
        $aryCustomerOrder['order_detail_created_date'] = date('Y-m-d H:i:s');
        $aryCustomerOrder['order_detail_created_date_date'] = date('d');
        $aryCustomerOrder['order_detail_created_date_month'] = date('m');
        $aryCustomerOrder['order_detail_created_date_year'] = date('Y');
        $aryCustomerOrder['order_detail_last_upate_date'] = date('Y-m-d H:i:s');
        $aryCustomerOrder['order_detail_process_date'] = date('Y-m-d H:i:s');
        $aryCustomerOrder['order_detail_method_payment'] = $aryParam['order_detail_method_payment'];
        $aryCustomerOrder['order_detail_method_delivery'] = $aryParam['order_detail_method_delivery'];
        $method_delivery = $this->getConfig('method_delivery');
        $method_payment = $this->getConfig('method_payment');
        $aryCustomerOrder['order_detail_payment_name'] = $method_payment[$aryParam['order_detail_method_payment']];
        $aryCustomerOrder['order_detail_delivery_name'] = $method_delivery[$aryParam['order_detail_method_delivery']];
        $aryCustomerOrder['order_detail_active'] = 1;
//        print_r($aryCustomerOrder);
        $intOk = $this->_objAdminModule->insertCustomerOrderInfo($aryCustomerOrder, $customerId);
//        if ($intOk == 1) {
        $listProductOrder = $aryParam['listProductOrder'];
        $aryProductId = explode(",", $listProductOrder);
        foreach ($aryProductId as $key => $value) {
            if ($value != '' && is_numeric($value)) {
                $aryProductOrder = array();
                $aryProductOrder['product_order_cookie_id'] = 'manage';
                $aryProductOrder['product_order_product_id'] = $value;
                $aryProductOrder['product_order_product_name'] = $aryParam['order_product_title_' . $value];
                $aryProductOrder['product_order_product_name_filter'] = $this->filterUnicode($aryParam['order_product_title_' . $value]);
                $aryProductOrder['product_order_product_name_search'] = $this->encodingUnicode($aryParam['order_product_title_' . $value]);
                $aryProductOrder['product_order_product_image'] = $aryParam['order_product_image_' . $value];
                $aryProductOrder['product_order_product_price_in'] = $aryParam['order_price_vnd_in_' . $value];
                $aryProductOrder['product_order_product_price'] = $aryParam['order_price_vnd_out_' . $value];
                $aryProductOrder['product_order_category_id'] = $aryParam['order_product_category_id_' . $value];
                $aryProductOrder['product_order_category_name'] = $aryParam['order_product_category_name_' . $value];
                $aryProductOrder['product_order_category_filter'] = $this->encodingUnicode($aryParam['order_product_category_name_' . $value]);
                $aryProductOrder['product_order_detail_id'] = $customerId;
                $aryProductOrder['product_order_total_product'] = $aryParam['order_product_number_' . $value];
                $aryProductOrder['product_order_product_unit'] = $aryParam['order_product_unit_' . $value];
                $aryProductOrder['product_order_total_price'] = $aryParam['order_product_number_' . $value] * $aryParam['order_price_vnd_out_' . $value];
                $aryProductOrder['product_order_create_date'] = date('y-m-d H:i:s');
                $aryProductOrder['product_order_process_date'] = date('y-m-d H:i:s');
                $aryProductOrder['product_order_last_update_date'] = date('y-m-d H:i:s');
                $aryCreator = $this->getSession('login');
                $aryProductOrder['product_order_creator_id'] = $aryCreator['member_id'];
                $aryProductOrder['product_order_creator_name'] = $aryCreator['member_full_name'];
                $aryProductOrder['product_order_create_date_date'] = date('d');
                $aryProductOrder['product_order_create_date_month'] = date('m');
                $aryProductOrder['product_order_create_date_year'] = date('Y');
                $aryProductOrder['product_order_active'] = 1;
                $intOk = $this->_objAdminModule->insertProductOrder($aryProductOrder);
            }
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _ORDER_SAVE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function updateCustomerInfoInOrder() {
        $aryParam = $this->getAllPostParams();
        $detailId = $this->getParam('detailId');
        $aryError = $this->validateAddProductOrder($aryParam);
        if (count($aryError) > 0) {
            $aryResult = array();
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            echo json_encode($aryResult);
            return;
        }
        $aryCustomerOrder = array();
        $aryCustomerOrder['order_detail_full_name'] = $aryParam['order_detail_full_name'];
        $aryCustomerOrder['order_detail_search_name'] = $this->encodingUnicode($aryParam['order_detail_full_name']);
        $aryCustomerOrder['order_detail_address'] = $aryParam['order_detail_address'];
        $aryCustomerOrder['order_detail_phone_number'] = $aryParam['order_detail_phone_number'];
        $aryCustomerOrder['order_detail_yahoo'] = $aryParam['order_detail_yahoo'];
        $aryCustomerOrder['order_detail_email'] = $aryParam['order_detail_email'];
        $aryCustomerOrder['order_detail_last_upate_date'] = date('Y-m-d H:i:s');
        $aryCustomerOrder['order_detail_method_payment'] = $aryParam['order_detail_method_payment'];
        $aryCustomerOrder['order_detail_method_delivery'] = $aryParam['order_detail_method_delivery'];
        $method_delivery = $this->getConfig('method_delivery');
        $method_payment = $this->getConfig('method_payment');
        $aryCustomerOrder['order_detail_payment_name'] = $method_payment[$aryParam['order_detail_method_payment']];
        $aryCustomerOrder['order_detail_delivery_name'] = $method_delivery[$aryParam['order_detail_method_delivery']];
        $aryConfig = array(
            'keyword' => 'where',
            'field' => 'order_detail_id',
            'value' => $detailId,
            'math' => '='
        );

        $intOk = $this->_objAdminModule->updateStatusOrder($aryCustomerOrder, $aryConfig);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['detailId'] = $detailId;
        $aryResult['message'] = _ORDER_PROCESS_SUCCESS;
        echo json_encode($aryResult);
    }

    public function validateAddProductOrder($aryParam) {
        $aryError = array();
        $objvalidator = new Validator();
        $flag = $objvalidator->validateEmpty($aryParam['order_detail_full_name']);
        if ($flag == true) {
            $aryError['order_detail_full_name_error'] = _ORDER_EMPTY_FULL_NAME;
        }
        $flag = $objvalidator->validateEmpty($aryParam['order_detail_address']);
        if ($flag == true) {
            $aryError['order_detail_address_error'] = _ORDER_EMPTY_ADDRESS;
        }
        $flag = $objvalidator->validateEmpty($aryParam['order_detail_phone_number']);
        if ($flag == true) {
            $aryError['order_detail_phone_number_error'] = _ORDER_EMPTY_PHONE_NUMBER;
        } else {
            $flag = $objvalidator->validatePhone($aryParam['order_detail_phone_number']);
            if ($flag == false) {
                $aryError['order_detail_phone_number_error'] = _ORDER_ERROR_FORMAT_PHONE_NUMBER;
            }
        }
        $flag = $objvalidator->validateEmpty($aryParam['order_detail_email']);
        if ($flag == false) {
            $flag = $objvalidator->validateMail($aryParam['order_detail_email']);
            if ($flag == false) {
                $aryError['order_detail_email_error'] = _ORDER_ERROR_FORMAT_MAIL;
            }
        }
        $flag = $objvalidator->validateEmpty($aryParam['order_detail_method_payment']);
        if ($flag == true) {
            $aryError['order_detail_method_payment_error'] = _ORDER_EMPTY_PAYMENT;
        }
        $flag = $objvalidator->validateEmpty($aryParam['order_detail_method_delivery']);
        if ($flag == true) {
            $aryError['order_detail_method_delivery_error'] = _ORDER_EMPTY_DELIVERY;
        }
        return $aryError;
    }

    public function searchOrder() {
        $aryParam = $this->getAllPostParams();
        $searchType = $this->getParam('searchType');
        $page = $this->getParam('page');
        switch ($searchType) {
            case "new":
                $orderType = 0;
                break;
            case "isProcess":
                $orderType = 1;
                break;
            case "isWait":
                $orderType = 2;
                break;
        }
        $order = $this->getParam('order');
        switch ($order) {
            case 1:
                $orderBy = 'ASC';
                break;
            case 2:
                $orderBy = 'DESC';
                break;
        }
        $aryConditions = array();
        $aryConditions['order_detail_search_name'] = trim(strip_tags($this->encodingUnicode($aryParam['search_order_customer_name'])));
        $aryConditions['order_detail_phone_number'] = trim(strip_tags($aryParam['search_order_customer_phone']));
        $aryConditions['order_detail_email'] = trim(strip_tags($aryParam['search_order_customer_email']));
        $aryConditions['order_detail_created_date_month'] = $aryParam['customer_order_search_month'];
        $aryConditions['order_detail_created_date_year'] = $aryParam['customer_order_search_year'];
        $aryConditions['order_detail_is_process'] = $orderType;
        $aryConditions['current_page'] = $page;
        $aryConditions['record_per_page'] = 10;
        $aryConditions['order'] = $orderBy;

        $intOk = $this->_objAdminModule->searchCustomerOrderDetail($aryConditions, $aryCustomer, 'order');

        foreach ($aryCustomer['data'] as $key => $value) {

            $aryDetailId[] = $value['order_detail_id'];
        }

        $strDetailId = implode(",", $aryDetailId);

        if ($strDetailId != '') {

            $intOk = $this->_objAdminModule->getProductOrderByDetailId($strDetailId, $aryProductOrder);
        }

        $this->setActionJSPaging("AdminController.searchOrder('$orderBy',");

        $strPaging = $this->AjaxPagination($aryCustomer['paging']);

        $this->assign('strPaging', $strPaging);

        $this->assign('aryOrderDetail', $aryCustomer['data']);

        $this->assign('aryProductOrder', $aryProductOrder);

        $this->assign('orderBy', $order);

        $this->assign('page', $page);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['orderContent'] = $this->getViewTemplate('admin/blackadmin', 'order_list_order_search');
        echo json_encode($aryResult);
    }

    public function getContactList() {
        $type = $this->getParam('type');
        $page = $this->getParam('page');
        switch ($type) {
            case "new":
                $readType = 0;
                break;
            case "isRead":
                $readType = 1;
                break;
        }
        $aryConditions = array();
        $aryConditions['read_type'] = $readType;
        $aryConditions['record_per_page'] = 1;
        $aryConditions['curent_page'] = $page;
        $intOk = $this->_objAdminModule->getListContact($aryContact, $aryConditions);
        $this->assign('aryContact', $aryContact['data']);
        $this->setActionJSPaging("AdminController.getContactList('$type',");
        $strPaging = $this->AjaxPagination($aryContact['paging']);
        $this->assign('strPaging', $strPaging);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'admin_list_contact');
        echo json_encode($aryResult);
    }

    public function viewCotactDetail() {
        $contactId = $this->getParam('contactId');

        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'customer_contact_id',
                'value' => $contactId,
                'math' => '='
            )
        );

        $aryData = array();
        $aryData['customer_contact_is_read'] = 1;
        $this->_objAdminModule->updateContact($aryConfig, $aryData);

        $intOk = $this->_objAdminModule->getContactDetail($contactId, $aryContact);
        $this->assign('aryContact', $aryContact[0]);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['content'] = $this->getViewTemplate('admin/blackadmin', 'contact_view_detail');
        echo json_encode($aryResult);
    }

    public function deleteContact() {
        $contactId = $this->getParam('contactId');
        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'customer_contact_id',
                'math' => '=',
                'value' => $contactId
            )
        );
        $aryUpdate = array();
        $aryUpdate['customer_contact_del_flag'] = 1;
        $intOk = $this->_objAdminModule->updateContact($aryConfig, $aryUpdate);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = 'Liên hệ đã được xoá.';
        echo json_encode($aryResult);
    }

    public function exportOrderToExcel() {
        $aryParam = $this->getAllPostParams();
        $searchType = $this->getParam('searchType');
        $page = $this->getParam('page');
        switch ($searchType) {
            case "new":
                $orderType = 0;
                $strOrder = 'Đơn hàng mới';
                break;
            case "isProcess":
                $orderType = 1;
                $strOrder = 'Đơn hàng đã xử lý';
                break;
            case "isWait":
                $orderType = 2;
                $strOrder = 'Đơn hàng đang chờ xử lý';
                break;
        }
        $order = $this->getParam('order');
        switch ($order) {
            case 1:
                $orderBy = 'ASC';
                break;
            case 2:
                $orderBy = 'DESC';
                break;
        }
        $aryConditions = array();
        $aryConditions['order_detail_search_name'] = trim(strip_tags($this->encodingUnicode($aryParam['search_order_customer_name'])));
        $aryConditions['order_detail_phone_number'] = trim(strip_tags($aryParam['search_order_customer_phone']));
        $aryConditions['order_detail_email'] = trim(strip_tags($aryParam['search_order_customer_email']));
        $aryConditions['order_detail_created_date_month'] = $aryParam['customer_order_search_month'];
        $aryConditions['order_detail_created_date_year'] = $aryParam['customer_order_search_year'];
        $aryConditions['order_detail_is_process'] = $orderType;
        $aryConditions['order'] = $orderBy;

        $intOk = $this->_objAdminModule->searchCustomerOrderDetail($aryConditions, $aryCustomer, 'export');

        foreach ($aryCustomer as $key => $value) {

            $aryDetailId[] = $value['order_detail_id'];
        }

        $strDetailId = implode(",", $aryDetailId);

        if ($strDetailId != '') {

            $intOk = $this->_objAdminModule->getProductOrderByDetailId($strDetailId, $aryProductOrder);
        }

        include dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'reviser.php';
        $resiver = new Excel_Reviser();
        $resiver->setInternalCharset('utf-8');
        $fileName = 'Thong ke don hang(' . date('d.m.Y') . ').xls';
        $sheetName1 = 'Thống kê chi tiết';
        $resiver->setSheetname(0, $sheetName1);
        $reportTilte = 'Thống kê đơn hàng';
        if (is_numeric($aryConditions['order_detail_created_date_month'])) {
            $reportTilte.=' tháng ' . $aryConditions['order_detail_created_date_month'];
        }
        if (is_numeric($aryConditions['order_detail_created_date_year'])) {
            $reportTilte.=' năm ' . $aryConditions['order_detail_created_date_year'];
        }

        $resiver->addString(0, 0, 0, $reportTilte);

        $strOrderTitle = 'Loại đơn hàng: ' . $strOrder;
        $resiver->addString(0, 1, 0, $strOrderTitle);

        foreach ($aryProductOrder as $key => $value) {
            $totalProduct+=$value['product_order_total_product'];
            $totalProfit+=$value['product_order_total_product'] * ($value['product_order_product_price'] - $value['product_order_product_price_in']);
        }

        $resiver->addString(0, 2, 0, 'Tổng sản phầm: ' . $totalProduct);

        $resiver->addString(0, 3, 0, 'Tổng lợi nhuận: ' . number_format($totalProfit, 0, ',', '.') . 'VNĐ');

        $timeTilte = 'Ngày xuất: ' . date('d/m/Y  -  H:i:A');
        $resiver->addString(0, 4, 0, $timeTilte);

//        $resiver->addImage(0, 0, 3, $this->getSubDomain() . '/images/them2/banner2.png');
        //row bắt đầu insert dữ liệu
        $rowStart = 9;
        //row kết thúc khi insert dữ liệu
        $maxRow = count($aryProductOrder);

        for ($i = 0; $i < $maxRow; $i++) {
            $row = $rowStart + $i;
            $resiver->addNumber(0, $row, 0, $i + 1, $rowStart, 0);
            $resiver->addString(0, $row, 1, date('d/m/Y', strtotime($aryProductOrder[$i]['product_order_create_date'])), $rowStart, 1);
            $resiver->addString(0, $row, 2, $aryProductOrder[$i]['product_order_product_name'], $rowStart, 2);
            $resiver->addImage(0, $row, 3, $this->getSubDomain() . '/images/upload/thumbnail/' . $aryProductOrder[$i]['product_order_product_image']);
            $resiver->addString(0, $row, 4, $aryProductOrder[$i]['product_order_category_name'], $rowStart, 4);
            $resiver->addString(0, $row, 5, number_format($aryProductOrder[$i]['product_order_product_price_in'], 0, ',', '.'), $rowStart, 5);
            $resiver->addString(0, $row, 6, number_format($aryProductOrder[$i]['product_order_product_price'], 0, ',', '.'), $rowStart, 6);
            $resiver->addString(0, $row, 7, $aryProductOrder[$i]['product_order_total_product'], $rowStart, 7);
            $resiver->addString(0, $row, 8, number_format($aryProductOrder[$i]['product_order_total_product'] * ($aryProductOrder[$i]['product_order_product_price'] - $aryProductOrder[$i]['product_order_product_price_in']), 0, ',', '.'), $rowStart, 8);
            for ($n = 0; $n < count($aryCustomer); $n++) {
                if ($aryCustomer[$n]['order_detail_id'] == $aryProductOrder[$i]['product_order_detail_id']) {
                    $resiver->addString(0, $row, 9, $aryCustomer[$n]['order_detail_full_name'], $rowStart, 9);
                    $resiver->addString(0, $row, 10, $aryCustomer[$n]['order_detail_address'], $rowStart, 10);
                    $resiver->addString(0, $row, 11, $aryCustomer[$n]['order_detail_phone_number'], $rowStart, 11);
                    $resiver->addString(0, $row, 12, $aryCustomer[$n]['order_detail_email'], $rowStart, 12);
                }
            }
            //
            $resiver->chgRowHeight(0, $row, 2000);
        }

        $template_file = $this->getTemplateFile('report_order.xls');

        $resiver->reviseFile($template_file, $fileName);
    }

    public function exportProductOrderToExcel() {
        include dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'reviser.php';
        $resiver = new Excel_Reviser();
        $resiver->setInternalCharset('utf-8');
        $fileName = 'Bao cao doanh so(' . date('Ymd') . ').xls';
        $sheetName1 = 'Thống kê chi tiết';
        $resiver->setSheetname(0, $sheetName1);
        $reportTilte = 'Báo cáo doanh số';
        $resiver->addString(0, 0, 0, $reportTilte);
        $timeTilte = 'Ngày ' . date('d-m-Y H:i:s');
        $resiver->addString(0, 0, 10, $timeTilte);

        $intOk = $this->_objAdminModule->getProductOrderData($aryProductOrder);
//        print_r($aryProductOrder);
        $intOk = $this->_objAdminModule->getCustomerOrderData($aryCustomer);
//        print_r($aryCustomer);
//        return;
        //row bắt đầu insert dữ liệu
        $rowStart = 9;
        //row kết thúc khi insert dữ liệu
        $maxRow = count($aryProductOrder);
        for ($i = 0; $i < $maxRow; $i++) {
            $row = $rowStart + $i;
            $resiver->addNumber(0, $row, 0, $i + 1, $rowStart, 0);
            $resiver->addString(0, $row, 1, date('d/m/Y', strtotime($aryProductOrder[$i]['product_order_process_date'])), $rowStart, 1);
            $resiver->addString(0, $row, 2, $aryProductOrder[$i]['product_order_product_name'], $rowStart, 2);
            $resiver->addImage(0, $row, 3, $this->getSubDomain() . '/images/upload/thumbnail/' . $aryProductOrder[$i]['product_order_product_image']);
            $resiver->addString(0, $row, 4, $aryProductOrder[$i]['product_order_category_name'], $rowStart, 4);
            $resiver->addString(0, $row, 5, number_format($aryProductOrder[$i]['product_order_product_price_in'], 0, ',', '.'), $rowStart, 5);
            $resiver->addString(0, $row, 6, number_format($aryProductOrder[$i]['product_order_product_price'], 0, ',', '.'), $rowStart, 6);
            $resiver->addString(0, $row, 7, $aryProductOrder[$i]['product_order_total_product'], $rowStart, 7);
            $resiver->addString(0, $row, 8, number_format($aryProductOrder[$i]['product_order_total_product'] * ($aryProductOrder[$i]['product_order_product_price'] - $aryProductOrder[$i]['product_order_product_price_in']), 0, ',', '.'), $rowStart, 8);
            for ($n = 0; $n < count($aryCustomer); $n++) {
                if ($aryCustomer[$n]['order_detail_id'] == $aryProductOrder[$i]['product_order_detail_id']) {
                    $resiver->addString(0, $row, 9, $aryCustomer[$n]['order_detail_full_name'], $rowStart, 9);
                    $resiver->addString(0, $row, 10, $aryCustomer[$n]['order_detail_address'], $rowStart, 10);
                    $resiver->addString(0, $row, 11, $aryCustomer[$n]['order_detail_phone_number'], $rowStart, 11);
                    $resiver->addString(0, $row, 12, $aryCustomer[$n]['order_detail_email'], $rowStart, 12);
                }
            }
            //
            $resiver->chgRowHeight(0, $row, 2000);
        }

        $template_file = $this->getTemplateFile('report_order.xls');

        $resiver->reviseFile($template_file, $fileName);
    }

    public function manageKeyword() {
        $intOk = 0;
        if ($this->checkConfigFile('home_data_store') == true) {
            $intOk = 1;
        }
        $aryData['intOk'] = $intOk;
        $aryData['data'] = $this->getDataConfigFile('home_data_store');
        echo json_encode($aryData);
    }

    public function saveHomeKeyword() {
        $aryData = $this->getAllPostParams();
        $aryKeyword = array();
        $aryKeyword['common_home_title'] = $this->removeHTML($aryData['common_home_title']);
        $aryKeyword['common_home_keyword'] = $this->removeHTML($aryData['common_home_keyword']);
        $aryKeyword['common_home_description'] = $this->removeHTML($aryData['common_home_description']);
        $aryKeyword['config_product_in_home'] = $this->removeHTML($aryData['config_product_in_home']);
        $aryKeyword['config_product_in_product'] = $this->removeHTML($aryData['config_product_in_product']);
        $aryKeyword['config_product_in_detail'] = $this->removeHTML($aryData['config_product_in_detail']);
        $aryKeyword['config_product_in_right'] = $this->removeHTML($aryData['config_product_in_right']);
        $aryError = $this->validateSaveHomeConfig($aryData);
        if(count($aryError) > 0){
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            $aryResult['message'] = 'Thông tin nhập vào bị thiếu hoặc bị sai';
            echo json_encode($aryResult);
            return false;
        }
        $this->buildConfigFile('home_data_store', $aryKeyword);
        
        $this->setFlagCacheFile('flag_cache_home_product');
        $this->setFlagCacheFile('flag_cache_right_product');

        $this->_objAdminModule->getCategoryId($aryCategory);
        foreach ($aryCategory as $key => $value) {
            $this->setFlagProductCache($value['category_id']);
        }

        $aryResult['intOk'] = 1;
        $aryResult['message'] = 'Thông tin đã được lưu.';
        echo json_encode($aryResult);
    }

    public function getInfoNewsPage() {
        $intOk = 0;
        if ($this->checkConfigFile('news_data_store') == true) {
            $intOk = 1;
        }
        $aryData['intOk'] = $intOk;
        $aryData['data'] = $this->getDataConfigFile('news_data_store');
        echo json_encode($aryData);
    }

    public function saveNewsPageInfo() {
        $aryData = $this->getAllPostParams();
        $aryResult = array();
        $aryConfig = array();
        $aryConfig['news_category_title'] = $this->removeHTML($aryData['news_category_title']);
        $aryConfig['news_category_keywords'] = $this->removeHTML($aryData['news_category_keywords']);
        $aryConfig['news_category_description'] = $this->removeHTML($aryData['news_category_description']);
        $aryConfig['config_news_in_home'] = (int)$this->removeHTML($aryData['config_news_in_home']);
        $aryConfig['config_news_in_news_category'] = (int)$this->removeHTML($aryData['config_news_in_news_category']);
        $aryConfig['config_news_in_new'] = (int)$this->removeHTML($aryData['config_news_in_new']);
        $aryConfig['config_news_in_views'] = (int)$this->removeHTML($aryData['config_news_in_views']);
        $aryError = $this->validateSaveNewsConfig($aryData);
        if(count($aryError) > 0){
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            $aryResult['message'] = 'Thông tin nhập vào bị thiếu hoặc bị sai';
            echo json_encode($aryResult);
            return false;
        }
        $this->buildConfigFile('news_data_store', $aryConfig);
        $pattern = 'tintuc*';
        $aryFile = $this->searchCacheFile($pattern);
        if(is_array($aryFile)){
            foreach ($aryFile as $key => $value) {
                $this->setFlagCacheToFile($value);
            }
        }
        $aryResult['intOk'] = 1;
        $aryResult['message'] = 'Thông tin đã được lưu.';
        echo json_encode($aryResult);
    }

    public function validateSaveHomeConfig($aryData) {
        $objValidator = new Validator();
        $aryError = array();
        if($objValidator->validateEmpty($aryData['common_home_title']) == true){
            $aryError['common_home_title_error'] = 'Tiêu đề không được để trống';
        }
        if($objValidator->validateEmpty($aryData['common_home_keyword']) == true){
            $aryError['common_home_keyword_error'] = 'Từ khóa không được để trống';
        }
        if($objValidator->validateEmpty($aryData['common_home_description']) == true){
            $aryError['common_home_description_error'] = 'Mô tả không được để trống';
        }
        //number
        if($objValidator->validateEmpty($aryData['config_product_in_home']) == true){
            $aryError['config_product_in_home_error'] = 'Số lượng không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_product_in_home']) == false){
                $aryError['config_product_in_home_error'] = 'Số lượng phải là số nguyên';
            }
        }
        if($objValidator->validateEmpty($aryData['config_product_in_product']) == true){
            $aryError['config_product_in_product_error'] = 'Số lượng không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_product_in_product']) == false){
                $aryError['config_product_in_product_error'] = 'Số lượng phải là số nguyên';
            }
        }
        if($objValidator->validateEmpty($aryData['config_product_in_detail']) == true){
            $aryError['config_product_in_detail_error'] = 'Số lượng không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_product_in_detail']) == false){
                $aryError['config_product_in_detail_error'] = 'Số lượng phải là số nguyên';
            }
        }
        if($objValidator->validateEmpty($aryData['config_product_in_right']) == true){
            $aryError['config_product_in_right_error'] = 'Số lượng không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_product_in_right']) == false){
                $aryError['config_product_in_right_error'] = 'Số lượng phải là số nguyên';
            }
        }
        return $aryError;
    }

    public function validateSaveNewsConfig($aryData) {
        $objValidator = new Validator();
        $aryError = array();
        if($objValidator->validateEmpty($aryData['news_category_title']) == true){
            $aryError['news_category_title_error'] = 'Tiêu đề không được để trống';
        }
        if($objValidator->validateEmpty($aryData['news_category_keywords']) == true){
            $aryError['news_category_keywords_error'] = 'Từ khóa không được để trống';
        }
        if($objValidator->validateEmpty($aryData['news_category_description']) == true){
            $aryError['news_category_description_error'] = 'Mô tả không được để trống';
        }
        if($objValidator->validateEmpty($aryData['config_news_in_home']) == true){
            $aryError['config_news_in_home_error'] = 'Số tin không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_news_in_home']) == false){
                $aryError['config_news_in_home_error'] = 'Số tin phải là số nguyên';
            }
        }
        if($objValidator->validateEmpty($aryData['config_news_in_news_category']) == true){
            $aryError['config_news_in_news_category_error'] = 'Số tin không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_news_in_news_category']) == false){
                $aryError['config_news_in_news_category_error'] = 'Số tin phải là số nguyên';
            }
        }
        if($objValidator->validateEmpty($aryData['config_news_in_new']) == true){
            $aryError['config_news_in_new_error'] = 'Số tin không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_news_in_new']) == false){
                $aryError['config_news_in_new_error'] = 'Số tin phải là số nguyên';
            }
        }
        if($objValidator->validateEmpty($aryData['config_news_in_views']) == true){
            $aryError['config_news_in_views_error'] = 'Số tin không được để trống';
        }else{
            if($objValidator->validateNumber($aryData['config_news_in_views']) == false){
                $aryError['config_news_in_views_error'] = 'Số tin phải là số nguyên';
            }
        }

        return $aryError;
    }

    public function getUserOnline() {
        $userOnline = $this->_objAdminModule->userOnline();
        echo json_encode($userOnline);
    }

}

?>
